Cannot read property of 'data'

Viewed 58

Hy everyone, i try to passing a data in a react native from this first page into the second page, and try using console log with params (route.params.data), but the result is Cannot read property of 'data',. when i try using this params (route) the data was successfuly transfer into the second page, but when i want to call the route.params.data , its error , This is my full code https://snack.expo.dev/@ryankurniantara/navigator-flatlist

enter image description here

enter image description here enter image description here enter image description here

1 Answers

in line 4, change const index = (route) to const index = ({route}).

import React from 'react'
import { StyleSheet, Text, View } from 'react-native'

const index = ({route}) => { // changed
    return (
        
            <View>
                <Text style={{fontSize: 21}}>
                    {route.params.data}
                </Text>
            </View>
        
    )
}

export default index

const styles = StyleSheet.create({})
Related