初學React:JSX文法

來源:互聯網
上載者:User

標籤: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文法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.