I know we can pass dynamically changing props in a JSX element like so:
<label htmlFor={dynamicId}/>
And we can pass static values like so:
<label htmlFor="staticId"/>
But what about the following:
<label htmlFor={'staticId'}/>
Is there an (albeit minor) performance overhead in the last line (internal React caching mechanism/ new string on every render)? Is the last line of code a bad practice or does it just not matter?
They're exactly equivalent. You can use Babel's playground to try it out:
[
<label htmlFor="staticId"/>,
<label htmlFor={'staticId'}/>
]
transpiles to
[
React.createElement("label", { htmlFor: "staticId" }),
React.createElement("label", { htmlFor: "staticId" })
];
No. It doesn't. React performance is very fast.
Using curly brace, you're telling to React to try to evaluate it and find a string. You're just taking a step longer.
At the end, result will be the same.
Though, I would recommend you to use without the curly brace if it is just a string and not a variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With