Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React/JSX attrs w/strings vs braces

Tags:

reactjs

jsx

The docs say that a JSX attributes with strings are the same as attributes with braces...

<Thing attr='val' /> === <Thing attr={'val'} />

I thought I read something that said only use braces when needed because strings are more performant, but I can't find the reference now. Is there an evaluation cost for braces?

like image 253
Ari Avatar asked Feb 13 '26 23:02

Ari


1 Answers

No there is no performance difference. Look at the code that's generated by each style:

<div first="abc" second={"def"}/>

// Compiles to:
React.createElement("div", { first: "abc", second: "def" });

Nicer to avoid unneeded braces though.

like image 90
gunn Avatar answered Feb 16 '26 13:02

gunn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!