如何进行导航。
我正在使用Typescript设置堆栈导航,这是我第一次使用Typescript。我有一个屏幕login.tsx
我想自定义导航栏。
import { useNavigation } from '@react-navigation/native';
import { StackNavigationProp } from '@react-navigation/stack';
import React from 'react';
import { SafeAreaView, Text } from 'react-native';
import { RootStackParamList } from '../typings';
type loginScreenProps = StackNavigationProp<RootStackParamList, 'Login'>;
const Login = () => {
const navigation = useNavigation<loginScreenProps>();
navigation.setOptions = {
headerTitle: 'Demo', // <-- ERROR
}
return (
<SafeAreaView>
<Text>Login</Text>
</SafeAreaView>
)
}
export default Login
我要去的错误是:
type'{headerTitle:string; }'不能分配输入'(选项: 部分)=&gt;空白'。对象字面可能只能 指定已知属性,并且“ headertitle”不存在类型 '(选项:部分)=&gt; void'。
rootstackParamlist
是简单offor type rootstackParamlist = {login:undefined; ...
如何在Typescript中实现它?
I'm setting up stack navigation using typescript and it's my first time working with typescript. I have a screen Login.tsx
in which I want to customize the navigation bar.
import { useNavigation } from '@react-navigation/native';
import { StackNavigationProp } from '@react-navigation/stack';
import React from 'react';
import { SafeAreaView, Text } from 'react-native';
import { RootStackParamList } from '../typings';
type loginScreenProps = StackNavigationProp<RootStackParamList, 'Login'>;
const Login = () => {
const navigation = useNavigation<loginScreenProps>();
navigation.setOptions = {
headerTitle: 'Demo', // <-- ERROR
}
return (
<SafeAreaView>
<Text>Login</Text>
</SafeAreaView>
)
}
export default Login
The error I'm going is:
Type '{ headerTitle: string; }' is not assignable to type '(options:
Partial) => void'. Object literal may only
specify known properties, and 'headerTitle' does not exist in type
'(options: Partial) => void'.
The RootStackParamList
is simple expor type RootStackParamList = { Login: undefined;...
How do I achieve it in typescript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
navigation.setoptions是一个函数,将对象作为输入
尝试进行此更改,并让我知道它是否已固定
navigation.setOptions is a function which takes object as an input
Try making this change and let me know if its fixed