我传递一个状态钩子到我的组件,并使用条件语句更改值。为什么会这样呢?
在我根组件中
const [done, setDone] = useState(0);
<FirstStep current={current} end={done} setEnd={setDone} />;
在组件中,我在useEffect中使用它
useEffect(() => {
if (
plateInput != null &&
mileageInput != null &&
makeInput != null &&
bodyInput != null &&
yearInput != null &&
kindInput != null &&
transmissionInput !== null
) {
console.log("object cleared");
setEnd(current);
// dispatch(setCompletedStep(current));
} else {
console.log("object is not cleared");
setEnd(current - 1);
// dispatch(setCompletedStep(current - 1));
}
}, [
plateInput,
mileageInput,
makeInput,
bodyInput,
yearInput,
kindInput,
transmissionInput,
]);
误差为TypeError: setEnd is not a function
。为什么会这样呢?
1条答案
按热度按时间jdg4fx2g1#
在
FirstStep
组件中接收props的时候看起来像是出错了,你需要确定一些要点UPDATE:尝试在
useEffect
内部设置状态,并使用回调函数检查当前