JSX In Depth
JSX In Depth
Fundamentally, JSX just provides syntactic sugar for the React.createElement(component, props, ...children)
function. The JSX code:
<MyButton color="blue" shadowSize={2}> Click Me </MyButton>
compiles into:
React.createElement( MyButton, {color: 'blue', shadowSize: 2}, 'Click Me' )
You can also use the self-closing form of the tag if there are no children. So:
<div className="sidebar" />
compiles into:
React.createElement( 'div', {className: 'sidebar'}, null )
If you want to test out how some specific JSX is converted into JavaScript, you can try out 登录查看完整内容