Why JSX?
Shawn had a great first day and he was just getting started with the next one at Adequate Consulting. With a mug of coffee, he startled Mike.
"Hey Mike, I saw that we used JSX for building our first component. Why should we use JSX when React has React.createElement
?"
"You can use React without using JSX. But JSX makes it easy to build React components. It reduces the amount of code required to write. It looks like HTML markup. Its syntax is simple and concise and it's very easy to visualize the components that are getting built."
"Take an example of the render function of a component without using JSX."
// render without JSX render: function(){ return(React.createElement("div", null, "Hello React World!")); }
"With JSX, it looks much better."
// render with JSX render: function(){ return <div> Hello React World </div>; }
"...