I am new to React. I am stuck on this, I would really appreciate help!
The parent component will pass the array to this child component. When I console.log (this.props.repairs), it shows me an array of 4. I try to update this.state.sortedDataList whenever the repairs array is passed. The .log console (this.state) is still showing sortedDataList as an empty array.
What am I doing wrong? Thanks a lot, appreciate any help.
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>
);
}
}
source
share