javascriptreact-nativeexpo

How to pass more than one params when navigating to another screen?


I am still learning React Native and I am stuck with navigating to a screen with some params. I know that to pass a param to another screen we can do it like this:

/item/[id].jsx

const ItemDetailsScreen = () => {
    const { id } = useLocalSearchParams();
    return (
        <View ...>
             ...
        </View>
    );
};

And in the previous screen we just call: router.push(``/item/${id}``)

Now, what if I need to pass two params: id and name?

Thank you.


Solution

  • You can pass the name in the params object:

    router.push(`/item/${id}`, { params: { name } })