首页 > 解决方案 > 反应导航:useIsFocused 使用失败测试用例

问题描述

我将 useIsFocused() 添加到我的文件中以适应焦点事件,例如

文件.js

import { useIsFocused, useNavigation } from "@react-navigation/native"

const navigation = useNavigation()    
const isFocused = useIsFocused()

useEffect(() => {
  getData(somedata)
}, [isFocused])

但是当我运行我的测试文件时,测试失败了

TypeError: navigation.isFocused is not a function

我在这里错过了什么吗?

标签: react-nativereact-navigation

解决方案


推荐阅读