使用状态更新

时间:2019-07-02 06:13:20

标签: reactjs routes use-effect

通过链接将对象链接消息从另一个页面传递到另一个页面。

<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在这里可能有用,但我不知道应该怎么做完成。有什么想法吗?

0 个答案:

没有答案
相关问题