by mmgutz · 5y ago · 0 comments
import cn from 'classnames'
const prevent = fn => e => e.preventDefault() && fn()
// don't forget key
{items.map(item =>
display && <SomeElement key="" onClick={prevent(foo)} className={cn(current: active)} />
)}And now you have to install and manage deps, import them, while your blob is still less readable because you have maps+lambda+&& to understand before even reaching what DOM element you are manipulating.
The premise of React is that composing primitives is better than having a high level tool to do the job: it's supposed to be more generic, more flexible, easier to learn.
In in my experience, it's true only in the case you don't have a well defined problem. But with frontend UI, we do. We know very well the problem to solve. Give me helpers. Give me wrappers. That's the only case where I welcome a DSL.
I don't want to have to think in functions and workflow in my template.
`onClick={prevent(() => newLambda(what, ever)}}`