Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

441
Vistas
Typescript: get `replace` from useNavigation() in react-navigation with react-native v6

This question resembles this how to use navigation.replace in TypeScript? which is for react-navigation 5.

I also read the docs https://reactnavigation.org/docs/typescript/#annotating-usenavigation

Tried a couple of different ways, but got more confused 🙃.

import { BottomTabScreenProps } from '@react-navigation/bottom-tabs'
import { CompositeScreenProps, NavigatorScreenParams } from '@react-navigation/native'
import { NativeStackScreenProps } from '@react-navigation/native-stack'
import { AxiosError } from 'axios'

declare global {
  namespace ReactNavigation {
    interface RootParamList extends RootStackParamList {}
  }
}

export type RootStackParamList = {
  SignIn: undefined
  ResetPassword: { email?: string } | undefined
  Root: NavigatorScreenParams<RootTabParamList> | undefined
  Modal: undefined
  Error: { error?: AxiosError | null } | undefined
  DevToolsSignIn: undefined
}

export type RootTabParamList = {
  Overview: undefined
  Returns: undefined
  Portfolio: undefined
  More: undefined
}

export type RouteName = keyof RootStackParamList | keyof RootTabParamList

export const routeTypeGuard = (route: RouteName) => route as keyof RootStackParamList

export type RootStackScreenProps<Screen extends keyof RootStackParamList> = NativeStackScreenProps<
  RootStackParamList,
  Screen
>

export type RootTabScreenProps<Screen extends keyof RootTabParamList> = CompositeScreenProps<
  BottomTabScreenProps<RootTabParamList, Screen>,
  NativeStackScreenProps<RootStackParamList>
>

then in a component I wish to tell typescript that I should be able to destruct replace from the useNavigation()

export default ({ route }: RootStackScreenProps<'ResetPassword'>) => {
  const { replace } = useNavigation<?🙃?>()
  const email = route.params?.email

  if (!email) replace('Error')

  return (
    <ScreenContainer>
      <Text style={{ color: 'hotpink' }}>{email}</Text>
    </ScreenContainer>
  )
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

this seems to do the trick

const { navigate, replace } = useNavigation<NativeStackNavigationProp<RootStackParamList>>()

that allows me to do things like:

replace('Root')

without any TS issues.

My misunderstanding was that the replace can't replace to any screen it wants - it can only replace to any screen within the navigation it's in.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda