【发布时间】:2020-03-12 05:56:54
【问题描述】:
我想知道如何使用 useEffect 之类的 componentWillReceiveProps。
我在我的反应应用程序中使用 redux。
所以当状态更新时我有一些 redux 状态,我不想在我的组件中执行某些功能。当我使用类组件时,我是这样做的:
componentWillReceiveProps(nextProps) {
if (nextProps.Reducer.complete !== this.props.Reducer.complete) {
someFunc();
}
}
现在我只使用功能组件和钩子。
现在我的组件是这样的:我正在尝试以这种方式进行操作,但无法正常工作。知道我在哪里弄错了吗?
function Component(props) {
const Reducer = useSelector(state => state.Reducer);
const someFunc = () => {
.....
}
useEffect(() => {
someFunc();
}, [Reducer.complete]);
}
export default Component;
【问题讨论】:
标签: javascript reactjs