4 ms·
I wish it could be possible to write this: const animal = "cat"; <Component {animal} /> equivalent to: <Component animal={animal} />
by hex13 10y ago
I wish it could be possible to write this:
const animal = "cat";
<Component {animal} />
equivalent to:
<Component animal={animal} />
- skosch 10y agoHow about <Component {{animal}} /> ? Because that should already work, no?
- alistairjcbrown 10y agoYou'd have to spread in the object, right? <Component {...{animal}} />
- hex13 10y agoI know, but it's too verbose for me. BTW there is a discussion about this: https://github.com/facebook/jsx/issues/23 https://github.com/facebook/jsx/issues/23
- skosch 10y agoYes, absolutely. Ignore what I wrote.
- sorahn 10y agoWe already do this when we have a lot of props to pass down. "A lot" usually means enough to take the line past 100 columns. const componentProps = {}; <Component {...componentProps} />
- blairanderson 10y agoThat is one of the suggestions
- drinchev 10y agoIMHO This is way too insignificant benefit for a breaking change with this magnitude. Using spread ( `{...{animal}}` ) is already working and it will stop working with the new syntax. On top of that killing two brackets and three dots will not give you huge performance / code-productivity benefit.