1
我目前正在尝试通过子组件更新我的组件状态,但回调函数告诉我状态未更新。
方法(loadModuleContent)反应更新状态奇怪的行为
export default class LayoutPage extends React.Component {
constructor() {
super();
this.startSession = this.startSession.bind(this);
this.loadModuleContent = this.loadModuleContent.bind(this);
this.state = {
content: undefined,
group: undefined,
title: undefined,
selectionIndex: undefined
}
}
static navigationOptions = {
header: null
};
loadModuleContent(_content, _title, _selectedIndex) {
console.log("Inserting index: " + _selectedIndex);
this.setState({
content: _content,
title: _title,
selectionIndex: _selectedIndex
}, console.log("State updated:" + this.state.selectionIndex));
}
...
您没有使用callback
按预期在setState
调用控制台日志
感觉很蠢....谢谢 –