Reputation: 1
I am new to ReactJS. I want to convert the class components into functional components. Please help.
I need help in converting unsafe_componentwillreceiveprops(nextprops) to useEffect
UNSAFE_componentWillReceiveProps(nextProps) {
this.props.getDirects(this.state.myDirects);
}
const getDirects = directs => {
setMyDirects(directs || []);
};
Upvotes: 0
Views: 349
Reputation: 10284
/*
UNSAFE_componentWillReceiveProps(nextProps) {
this.props.getDirects(this.state.myDirects);
}
*/
function yourComp({ getDirects }){
const [myDirects, setMyDirects] = React.useState();
React.useEffect(() => {
getDirects(myDirects);
}, [getDirects, myDirects]);
return(...);
}
Upvotes: 0