“字串”型別的引數不能分配給“{ key: string;”型別的引數。引數?:從不;合并?:布林值;} | { 名稱:從不;鍵?:字串;引數:從不;合并?:布林值;}'.ts(2345)
當我們無法在 react-native an help 中使用 typescript 導航到另一個螢屏時,總是會發生這種情況?代碼示例:
<Button text="go to page 1" onPress={()=>navigation.navigate("page_2")} />
在此處輸入圖片說明
uj5u.com熱心網友回復:
由于錯誤訊息建議嘗試傳遞包含“key”屬性的物件。
<Button text="go to page 1" onPress={()=>navigation.navigate({key:"page_2"})} />
uj5u.com熱心網友回復:
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>
)
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/367195.html
上一篇:ReactNavigation6:從子導航器內的螢屏覆寫父導航器的標題配置
下一篇:在PressOut上反應原生
