我在访问 useEffect() Hook 内的 props.location.state 时遇到问题。它是这样的:
useEffect((props) => {
console.log("location: :", props.location.state);
}, [props])
显示 props.location.state 未定义。为什么它是未定义的以及如何设置它?
谢谢。
最佳答案
我认为您正在使用回调中的 props
,而不是您想要使用的 props
。您必须从回调中删除参数 props
。
useEffect(() => {
console.log("location: :", props.location.state);
}, [props])
关于javascript - React 应用程序显示 props.location.state 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61111724/