2015-08-03 57 views
0

我有這樣的代碼,這是我從看着教程這裏放在一起: https://www.bignerdranch.com/blog/how-to-use-facebooks-react-library-to-build-UIs/爲什麼mountNode不會反應工作?

<script type="text/jsx"> 
/** @jsx React.DOM 
*/ 
var HelloMessage = React.createClass({ 
    render: function() { 
    return (
     <div> 
     <h1>Greetings, Human {this.props.name} </h1> 
      <p> 
       Would you like to play a game?<br /> 
       How about a nice game of 
       <a href="http://nsa.gov"> Chess</a>? 
      </p> 
     </div> 
    ); 
    } 
}); 

React.renderComponent(
    HelloMessage(), 
    document.getElementById('rcomponent') 
); 

當我改變的最後部分:

React.renderComponent(<HelloMessage name="John" />, mountNode); 

我得到這個錯誤消息:

Uncaught ReferenceError: mountNode is not defined 

任何人都可以向我解釋發生了什麼?我已經看了至少5個其他的例子,它們的語法和佈局都一樣,所以我不知道發生了什麼問題。謝謝!

回答

3

使用有效的節點,而不是mountNode

插入該行的body標籤

<div id="app"></div> 

之後再更換

document.getElementById('example') 

,而不是mountNode

React.renderComponent(<HelloMessage name="John" />, document.getElementById('example'));