首页 > 代码库 > React getInitialState desc
React getInitialState desc
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <script src="../../build/react-with-addons.js"></script> <script src="../../build/JSXTransformer.js"></script></head><body> <div id="demo"></div> <hr> <div id="app"></div> <div id="likeBtn"></div> <script type="text/jsx"> /** @jsx React.DOM */ var HelloMessage = React.createClass({ render: function () { return <div>Hello, {this.props.name}</div>; } }); React.renderComponent(<HelloMessage name="Jack"/>, document.getElementById(‘demo‘)); </script> <script type="text/jsx"> /** @jsx React.DOM */ var App = React.createClass({ componentDidMount: function () { console.log(this.props.children); }, render: function () { return <div><span></span></div> } }); React.renderComponent(<App></App>, document.getElementById(‘app‘)); </script> <script type="text/jsx"> /** @jsx React.DOM */ var LikeButton = React.createClass({ getInitialState: function () { return { liked: false }; }, handleClick: function (event) { this.setState({ liked: !this.state.liked }); }, handleMouseEnter: function () { console.log(this); }, render: function () { var text = this.state.liked ? ‘like‘ : ‘unlike‘; return ( <p onClick= {this.handleClick} > You {text} Click to toggle </p> ); } }); React.renderComponent(<LikeButton />, document.getElementById(‘likeBtn‘)); </script></body></html>
React getInitialState desc
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。