我在访问useEffect()挂钩中的props.location.state时遇到麻烦。它是这样的:
useEffect((props) => {
console.log("location: :", props.location.state);
}, [props])
它显示props.location.state是未定义的。为什么它是未定义的,我该如何设置?
谢谢。
我在访问useEffect()挂钩中的props.location.state时遇到麻烦。它是这样的:
useEffect((props) => {
console.log("location: :", props.location.state);
}, [props])
它显示props.location.state是未定义的。为什么它是未定义的,我该如何设置?
谢谢。
I think you are using the
props
from callback, not thatprops
what you want to use. You have to remove argumentprops
from callback.The second argument to
useEffect
is an array of values, the if any one of them changes, the effect should run. As a best practice, you should only put in values here that you need for the effect. I would change it to:Take a look at the React
onEffect
docs for more information: https://reactjs.org/docs/hooks-effect.html