What do curly braces mean in JSX (React)?

前端 未结 4 1834
终归单人心
终归单人心 2020-11-29 01:26

For an example, to set a style in react you could do

var css = {color: red}

and

Hello world

4条回答
  •  生来不讨喜
    2020-11-29 02:06

    If you don't use the variable css, the JSX could look like this:

    Hello world

    I guess you are confused about the double curly braces.

    so you know that the curly braces in JSX means process the inner value in JavaScript, so the outer braces is used exactly for this purpose.

    But the style property accepts an object. And an object also needs another pair of curly braces to wrap it up. That's the purpose for the inner ones.

提交回复
热议问题