I am new to React hooks. So, I wanted to implement componentWillReceiveProps with React hooks. I used React.useEffect() like so:
React.useEffect(() => {
console.log(props.authLoginSuccess); // initially called every time, the component renders
}, [props.authLoginSuccess]);
return ( //JSX...)
onst mapStateToProps = (state: any): StateProps => {
return {
authLoginSuccess: selectAuthLoginSuccess(state) //used selector to select authLoginSuccess
};
};
export default connect(
mapStateToProps,
// mapDispatchToProps
{ authLogin, toggleLoadingStatus }
)(Auth);
The problem is, useEffect is called each time the component renders initially, which I don't want. I only want it to render, when "props.authLoginSuccess" changes.
props.authLoginSuccess?useEffect(() => { console.log('mounted!'); return () => console.log('unmounted');}, [])