javascript - React tutorial error rendering CommentForm and CommentList -
i started official react tutorial , seem stumbling upon error prevents browser showing content, it's stupid typo, can't seem find it. in var commentbox
when remove <commentlist />
, <commentform />
, element <h1>comments</h1>
appears, when add them nothing appears in browser, <h1>comments</h1>
. overlooking, ideas? thanks!
my code
<div id="content"></div> <script type="text/jsx"> var commentbox = react.createclass({ render: function () { return ( <div classname="commentbox"> <h1>comments</h1> <commentlist /> <commentform /> </div> ); } }); react.render( <commentbox />, document.getelementbyid('content') ); var commentlist = react.createclass({ render: function () { return ( <div classname="commentlist"> hello, world! commentlist. </div> ); } }); var commentform = react.createclass({ render: function () { return ( <div classname="commentform"> hello, world! commentform. </div> ); } }); </script>
you need move var declaration of "commentlist" , "commentform" top of script tag, above "commentbox". because in javascript there hoisting. put example in github: https://github.com/josemato/stackoverflow/blob/master/reactjs-tutorial/index.html
Comments
Post a Comment