undefined is not an object (evaluating 'route.params.id')

3339 views react-native
2

i have created two component in the first component I have an object and I want to display on the the other screen component I passed it as parameter but when I liked it through error here is my code

const Tweets = ({ navigation }) => (
  <ExpoScreen>
    <Text>Tweets</Text>
    <Button
      title="View Tweet"
      onPress={() => navigation.navigate("TweetDetails", { id: 1 })}
    />
  </ExpoScreen>
);

const TweetDetails = ({ route }) => (
  <ExpoScreen>
    <Text>Tweets details {route.Params.id}</Text>
  </ExpoScreen>
);

const Stack = createStackNavigator();
const StackNavigator = () => (
  <Stack.Navigator initialRouteName="Tweets">
    <Stack.Screen name="Tweets" component={Tweets} />
    <Stack.Screen name="TweetDetails" component={TweetDetails} />
  </Stack.Navigator>
);

export default function App() {
  return (
    <NavigationContainer>
      <StackNavigator />
    </NavigationContainer>
  );
}

enter image description here

answered question

why is your params capital? like P in their capital

thanks issue of capital p

params not Params. It is not capital, Also you need control it too: <Text>Tweets details {route?.params?.id}</Text>

1 Answer

9

I believe the issue is like P is capital in your params.

Hopeit helps. feel free for doubts

posted this

Have an answer?

JD

Please login first before posting an answer.