我是比较新的反应,并从一些教程开始我被困在这一点,我无法确定为什么无法读取属性' __ reactInternalInstance $ npc92gvg9bpy20iee3fpqfr'抛出null 错误。这是我的代码:
var Profile = React.createClass({
getInitialState: function() {
return {
count: 0,
task: '',
gists: []
};
},
addTask: function(e) {
var items = this.state.items.concat([this.state.task]);
var task = ''
this.setState({ items, task });
e.preventDefault();
},
onChange: function(e) {
var task = e.target.value;
this.setState({ task });
},
getDefaultProps: function() {
return {
path: 'http://lh3.googleusercontent.com/-CdI8n3eKqBY/AAAAAAAAAAI/AAAAAAAAAAA/AKTaeK-Iti8fjN610AAfj53Twp1R8PMNiQ/s96-c-mo/photo.jpg',
items: []
};
},
increment: function() {
var count = this.state.count + 1;
this.setState({ count });
},
decrement: function() {
var count = this.state.count - 1;
if(count < 0) {
count = 0
}
this.setState({ count });
},
render: function() {
var displayTask = (task) => <li>{ task }</li>;
var newGist = function(gist) {
return <Gist username={gist.username} url={gist.url} />
};
return (
<div>
<h1>Counter : { this.state.count }</h1>
<button onClick = { this.increment }>+1</button>
<button onClick = { this.decrement }>-1</button>
<a href={ this.props.path }><img src={ this.props.path } /></a>
<h1>My Tasks</h1>
<Profile items={this.state.items} />
<form onSubmit={this.addTask}>
<input type="text" placeholder="Enter New Task" onChange={this.onChange} value={this.state.task} />
<button>Add Task</button>
</form>
<ul>
{ this.props.items.map(displayTask) }
</ul>
<h1>GistBox</h1>
{ this.state.gists.map(newGist) }
{this.props.usernames}'s' last Gist is <a href={this.props.url}>here</a>.
</div>
);
}
});
ReactDOM.render(<Profile />, document.body);