我在我的應用程序下面的代碼...試圖調用地圖,但它不是一個數組
componentWillMount(){
this.ref = base.syncState('/tasks', {
context: this,
state: 'tasks'
});
}
...
renderTasks() {
return this.state.tasks.map(name => (
<Task
key={name}
name={name}
removeTask={this.removeTask}
/>
));
}
render() {
return (
<div className="TaskList">
<h3>TODO List</h3>
{this.renderTasks()}
<TaskInput addTask={this.addTask}/>
</div>
);
}
}
我的應用程序得到的錯誤是... TypeError: this.state.tasks.map is not a function
我的理解是,因爲任務不是一個數組,但我不知道爲什麼?如果我在renderTasks中添加console.log(this.state.tasks),它會顯示兩次,第一次是[],但下一次是{}。我也不明白。這裏是完整的代碼:https://gist.github.com/marklocklear/e88f75e7e973f67490f6b3034c9eeeff
在此先感謝!
什麼是'base.syncState'在做什麼? –