我是React的新手.我坚持这个,真的很感激一些帮助!
父组件将数组传递给此子组件.当我在console.log(this.props.repairs)时,它向我显示了一个4的数组.每当传入修复数组时,我都会尝试更新this.state.sortedDataList.控制台.log(this.state)仍然是将sortedDataList显示为空数组.
我究竟做错了什么?非常感谢,感谢任何帮助.
class Repairs extends React.Component {
constructor(props) {
super(props);
this.state = {
sortedDataList: []
};
}
componentWillReceiveProps(nextProps) {
if(this.props != nextProps) {
this.setState({
sortedDataList: this.props.repairs
});
}
}
render() {
console.log(this.props);
console.log(this.state);
return (
<div></div>
);
}
}
Run Code Online (Sandbox Code Playgroud) reactjs ×1