通过链接将对象链接消息从另一个页面传递到另一个页面。
<Link
to={{
pathname: '/study-desk',
state: {
messageFromLibrary: 'notesPane',
},
}}
>
然后接收并使用它在另一个页面上设置状态。
useEffect(() => {
if (typeof (props.location.state) !== 'undefined' || props.location.state != null) {
const { messageFromLibrary } = props.location.state;
setPane(messageFromLibrary);
} else {
// error handling, if message undefined
setPane('default');
}
}, []);
收到错误消息:这是一个无操作,但它表明您的应用程序中存在内存泄漏。要修复,请取消该componentWillUnmount
方法中的所有订阅和异步任务。可以看到在钩子中使用:return () =>
在useEffect
这里可能有用,但我不知道应该如何完成。有任何想法吗?