首页 > 解决方案 > 带有 useEffect 的 useFocusEffect 随机返回警告“不支持 'route' 对象的属性”

问题描述

我有这个效果,它在离开屏幕时设置一个状态。当状态设置为空时,它会触发一个关闭底部工作表的函数(警报)

useFocusEffect(
  React.useCallback(() => {
    return () => {
      setAlert(null);
    };
  }, [setAlert])

我在移动到另一个屏幕时随机收到此警告**,而警报底部表打开**:Accessing the 'state' property of the 'route' object is not supported. If you want to get the focused route name, use the 'getFocusedRouteNameFromRoute' helper instead: https://reactnavigation.org/docs/screen-options-resolution/#setting-parent-screen-options-based-on-child-navigators-state

当我禁用它useFocusEffect时,警告就会消失。

我究竟做错了什么?

标签: react-nativereact-navigation

解决方案


推荐阅读