<Button text= "go to page 2" onPress={()=>navigation.navigate( "page_2" )} />



类型为"string"的参数不可分配给类型为"{key:string;params?:never;merge?:boolean;}|{name:never;key?:string;params:never;合并?:boole;}"的参数。ts(2345(

当我们无法使用react native中的typescript导航到另一个屏幕时,总是会发生这种情况?代码示例:

<Button text="go to page 1" onPress={()=>navigation.navigate("page_2")} />

在此处输入图像描述

正如错误消息所建议的,尝试传递一个包含"键";所有物

<Button text="go to page 1" onPress={()=>navigation.navigate({key:"page_2"})} />
import React, { FC } from "react"
import { observer } from "mobx-react-lite"
import { ViewStyle } from "react-native"
import { Button, Screen, Text } from "../../components"
import { useNavigation } from "@react-navigation/native"
// import { useStores } from "../../models"
import { color } from "../../theme"
import { NavigationInjectedProps } from "react-navigation";
const ROOT: ViewStyle = {
backgroundColor: color.palette.black,
flex: 1,
}
export interface Page1Props extends NavigationInjectedProps<{}> {

} //u should create a interface of props 
export const Page1Screen :FC<Page1Props> = observer(function Page1Screen(props)  {// then use the interface for the functional component
// Pull in one of our MST stores
// const { someStore, anotherStore } = useStores()
// Pull in navigation via hook
//const navigation = useNavigation()
return (
<Screen style={ROOT} preset="scroll">
<Text preset="header" text="page 1" />
<Button text="go to page 2" onPress={()=>props.navigation.navigate("page_2")} />
</Screen>
)
})

最新更新