標籤:function 筆記 box nts document rac 語句 javascrip element
這是本人初學React做的學習筆記;講的不是很深,只算是簡單的進行介紹。
這是一個小系列。都是在同一個模板中搭建的,但是代碼是不能正常執行的。
>>第一個組件.js
‘use strick‘/*===========================JavaScript的XML文法========================*/var CommentBox = React.createClass({render:function () {return (<div className="CommentBox">Hello, world!I am a CommentBox.</div>);}});ReactDOM.render(<CommentBox />,document.getElementById(‘content‘));/*=====================以上JS語句將被翻譯為;==========================*/var CommentBox = React.createClass({displayName: ‘CommentBox‘,render: function() {return (React.createElement(‘div‘, {className: "CommentBox"},"Hello, world!I am a CommentBox."));}});ReactDOM.render(React.createElement(commentBox, null),document.getElementById(‘content‘));/*=============================撰寫組件===================================*/var CommentList = React.cracteClass({render: function() {return (<div className="commentList">Hello, React`s World!I am a Commentlist.I am form Lao Zhao.</div>);}});var CommentForm = React.createClass({render: function() {return (<div className="commentForm">Hello React`s World!I am a CommentForm.I am from Lao Zhao.</div>);}});/*==============================更新群組件===================================*/var CommentBox = React.createClass({render: function() {return (<div className="commentBox"><h1>Comments</h1><CommentList /><CommentForm /></div>);}});/*==============================使用道具=======================================*/var Comment = React.createClass({render: function() {return (<div><h2 className="commentAuthor">{this.props.author}</h2>{this.props.children}</div>);}});/*===============================組件屬性===========================================*/var CommentList = React.createClass({render: function() {return (<div className="commentList"><Comment author="Zhao Gaosheng">This is one comment.</Comment><Comment author="Gaosheng">This is *another*comment.</Comment></div>);}});
這裡只是簡單讓大家感受一下JSX的文法氛圍。
初學React:JSX文法