skip to Main Content

I’m trying to pass the pressed product data to the product screen using RN expo route but I’m getting
TypeError: Cannot read property ‘params’ of undefinedenter image description here

// Stack

    <Stack screenOptions={{headerShown: false}}>
      <Stack.Screen name="(tabs)" />
      <Stack.Screen name="(prod)" />
    </Stack>

// Product Screen

const ProductScreen = props => {
  const getProduct = props?.route?.params?.item;
  console.log("Products ", getProduct);
  return (
    <View>
      <Text>ProductScreen</Text>
    </View>
  );
};

2

Answers


  1. Below is the Expo Router documentation for you.

    Passing parameters to the routes

    Login or Signup to reply.
  2. import { router, useLocalSearchParams } from 'expo-router'
    

    Using hook

    onPress={() => {
              router.push({ pathname: "/", params: { post: "random", id, other } });
            }}
    

    Link component

    <Link
            href={{
              pathname: "/",
              params: { post: "random", id, other },
            }}
          >
            Go to Details
          </Link>
    

    Getting the data in the destination route

     const { post,id, other } = useLocalSearchParams();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search