我是 React 钩子的新手。所以,我想用 React 钩子实现 componentWillReceiveProps。我像这样使用 React.useEffect() :
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);
问题是,每次组件最初呈现时都会调用 useEffect,这是我不想要的。我只希望它在“props.authLoginSuccess”更改时呈现。