问题描述
在 Navigating without the navigation prop 之后,我无法在打字稿中使引用可变以分配 current
。面对错误
无法分配给“current”,因为它是只读属性。
"react": "17.0.1","react-native": "0.64.0","@types/react-native": "^0.64.0",
在 index.js
我有
PushNotification.configure({
onNotification: (notification) => {
navigatetoScreen("screenName",{params})
notification.finish(PushNotificationIOS.FetchResult.NoData);
},/* othe config attributes */
});
在navigation.tsx
我有
<NavigationContainer ref={navigationContainerRef} onReady={() => (navigationReady.current = true)}>
/* drawer stack ...*/
</NavigationContainer>
引用是从 ntfService.ts
导出的值
export const navigationContainerRef = React.createRef<NavigationContainerRef | null>();
export let navigationReady = React.createRef<boolean>();
export const navigatetoScreen = (scrName:string,params:{id:number}) => {
if (navigationContainerRef.current && navigationReady.current) {
navigationContainerRef.current.navigate(scrName,params);
} else {
/** */
}
};
遵循 GitHub issues 中的答案,使用 |null 定义 ref 类型应该使其可变。但在 useRef
上似乎是这样。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)