Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to do navigation.setOptions in typescript

$
0
0

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 onlyspecify 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?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>