官术网_书友最值得收藏!

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("p", 
                               null, 
                               "Hello React World!"));
}

"With JSX, it looks much better."

// render with JSX
render: function(){
    return <p>
      Hello React World
    </p>;
  }

"Compared to the previous non-JSX example, the JSX code is much more readable, easy to understand, and close to the actual HTML markup."

"The similarity between JSX and HTML markup means that non-developers such as UI and UX designers in the team can contribute to a project using JSX. Having XML-like tag syntax also makes reading large component trees easier compared to the function calls or object literals in JavaScript." explained Mike.

"Yeah. The syntax does look familiar. We will be using JSX all the way in our projects right?"

"Yes, we will", remarked Mike.

主站蜘蛛池模板: 兴城市| 正阳县| 邵阳市| 龙川县| 四子王旗| 柘荣县| 宁德市| 荃湾区| 桦甸市| 桦南县| 宁远县| 壤塘县| 闻喜县| 会宁县| 宝鸡市| 常州市| 万山特区| 湘潭县| 顺平县| 长葛市| 那曲县| 龙海市| 和平区| 新昌县| 惠来县| 抚宁县| 友谊县| 章丘市| 宽城| 稷山县| 宁波市| 宜春市| 吉木乃县| 洪江市| 讷河市| 洱源县| 马山县| 马鞍山市| 漳州市| 睢宁县| 浪卡子县|