首页 > 解决方案 > 反应原生聆听组件的选项卡更改?

问题描述

在 React Native 中是否可以监听组件中的选项卡更改?

  useEffect(() => {

    return () => console.log('unmount?')
  }, [navigation])

当我更改选项卡并离开组件时,有什么可以检测到的使用效果吗?我猜它没有卸载,但我需要知道用户何时离开屏幕

标签: javascriptreactjsreact-native

解决方案


You can use

navigation.isFocused

to know which screen is focussed


推荐阅读