Uncaught ReferenceError: mountNode не определен
Прости меня, я искал всюду, и я новичок в реакциях и тестирую примеры. У меня есть ошибка
Uncaught ReferenceError: mountNode is not defined
Я следую примеру отсюда http://facebook.github.io/react/tips/initial-ajax.html
и мой код выглядит следующим образом
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css' />
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="/javascripts/reactjs/react.js"></script>
<script src="/javascripts/reactjs/JSXTransformer.js"></script>
</head>
<body>
<h1><%= title %></h1>
<p>Welcome to <%= title %></p>
<div id="example"></div>
<script src="/javascripts/reactjs/build/helloworld.js"></script>
<script type="text/jsx">
/** @jsx React.DOM */
var UserGist = React.createClass({
getInitialState: function() {
return {
username: '',
lastGistUrl: ''
};
},
componentDidMount: function() {
$.get(this.props.source, function(result) {
var lastGist = result[0];
this.setState({
username: lastGist.owner.login,
lastGistUrl: lastGist.html_url
});
}.bind(this));
},
render: function() {
return (
<div>
{this.state.username}last gist is
<a href={this.state.lastGistUrl}>here</a>.
</div>
);
}
});
React.renderComponent( <UserGist source="https://api.github.com/users/octocat/gists" />, mountNode );
</script>
</body>
</html>
Заранее благодарю вас!
Ответы
Ответ 1
Вам нужно указать React, где смонтировать компонент <UserGist />
. Вероятно, вы захотите заменить mountNode
на document.getElementById('example')
, чтобы обратиться к вашему элементу <div id="example"></div>
:
React.render(
<UserGist source="https://api.github.com/users/octocat/gists" />,
document.getElementById('example')
);
Ответ 2
Будучи принятым ответом, я хотел бы добавить одно: не забудьте включить ссылки на все необходимые js libs в разделе html head, если вы тестируете это из "папки примеров экземпляров"
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://npmcdn.com/[email protected]/dist/react.js"></script>
<script src="https://npmcdn.com/[email protected]/dist/react-dom.js"></script>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>