Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

320
Visualizações
Uncaught TypeError: Cannot read properties of undefined (reading 'navigate')

I am new to react native and react navigation and I get this error.

Uncaught TypeError: Cannot read properties of undefined (reading 'navigate')

I don't understand my because I am just using the same code which already worked, but now it's not working.

I am trying to make a back arrow that send you back to the MachineList screen.

//doesn't work
const AddMachineDetails = ({route}, props) => {

...

<TouchableOpacity onPress={() => props.navigation.navigate("MachinesList")}>
        <BackArrow />
 </TouchableOpacity>

So when I press my backarrow it send me this error:

Uncaught TypeError: Cannot read properties of undefined (reading 'navigate')

Here is my Navigation file:

import MachinesList from '../components/MachinesList'
import AddMachineDetails from '../components/AddMachineDetails';

...

function MachineListStackScreen() {
    return(
        <Stack.Navigator screenOptions={{headerShown: false}}>
            <Stack.Screen name='MachinesList' component={MachinesList}/>
            <Stack.Screen name='AddMachineDetails' component={AddMachineDetails}/>
        </Stack.Navigator>
    )
}

...

I think the problem is somewhere in this code, but if not, I'll show you more of my code

Here is an example where my navigation.navigate work perfectly:

//no specific imports  (but works)

const MachinesList = (props) => {

...


<TouchableOpacity style={styles.machineBox} onPress={() => props.navigation.navigate('AddMachineDetails', {item})}>
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You have to desctruct the props argument.

const AddMachineDetails = ({route, ...props}) => { ... }  

or

const AddMachineDetails = ({route, navigation, ...props}) => { ... }  // then straightly use the *navigation*
about 4 years ago · Juan Pablo Isaza Relatório

0

The issue is here ({route}, props) =>.

You are destructuring the first argument, but there aren't other parameters passed and that's why "props" variable is undefined.

You have two solutions:

  1. Just use props:
const AddMachineDetails = (props) => {
  1. Destructure props:
const AddMachineDetails = ({route, navigation, ...props}) => {
...

<TouchableOpacity onPress={() => navigation.navigate("MachinesListDetails")}>
       <BackArrow />
</TouchableOpacity>
about 4 years ago · Juan Pablo Isaza Relatório

0

Optional chaining can be useful in future to prevent errors in runtime. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda