2 ms·
To be fair, most of use `classnames` and likely have a higher order function for prevent import cn from 'classnames' const prevent = fn => e => e.preve
by mmgutz 5y ago
To be fair, most of use `classnames` and likely have a higher order function for prevent
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)} />
)}
- BiteCode_dev 5y agoCongrats, you are reinventing part of VueJS, in a non standard, untested, undocumented, less readable way. But wait, you need another lambda to pass arguments to foo() should it change. And another wrapper for stopPropagation. And so on, and so on. 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.
- mmgutz 5y agoChanging the lambda? `onClick={prevent(() => newLambda(what, ever)}}`