在没有导航道具的导航之后,我无法在打字稿中使引用可变以分配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 问题中的答案,使用 |null 定义 ref 类型应该使其可变。但似乎就useRef
这样。