JSX Syntax - kitiya/react-29 GitHub Wiki
1. Curly braces { } are special syntax in JSX. It is used to evaluate a JavaScript expression during compilation. A JavaScript expression can be a variable, function, an object, or any code that resolves into a value.
Let’s take an example. Evaluating a JavaScript variable
const yellowStyle={color: 'yellow'}
<Star style={yellowStyle} />which is same as
<Star style={{color: 'yellow'}} />() => ({ name: 'Amanda' }) // Shorthand to return an objectThat is equivalent to
() => {
return { name : 'Amanda' }
}2. Parenthesis are used to group multiline of codes on JavaScript return statement so to prevent semicolon inserted automatically in the wrong place.
class StarsComponent {
constructor(size) {
this.size = size;
}
render() {
return (<div>
*
</div>) // <--JavaScript engine inserts semicolon here
}
}