So I have been using
import { useRoute } from '@react-navigation/native'
const ProductInfo = () => {
const {
params: {
category,
coreProduct,
subProduct
},
} = useRoute()
return (
<Text>{category}</Text>
<Text>{coreProduct}</Text>
<Text>{subProduct}</Text>
{...}
to carry over choices the user would make with buttons, or image selections through an app, and for the most part, I have no issue with this. for instance, I have been able to carry over choices from three separate screens, display the previous screens choice in the title, (Example: Men’s > Shirt > Casual Wear) and onto the next page, but for some reason bringing this back to the main page to display all three choices brings up a Render Error of "undefined is not an object (evaluating ‘_useRoute$params.category’)" I happened to fix this once before, but then after some edits made to the choice screens it has reappeared and cannot figure out the problem.
If more code example is needed please let me know and I can add an example of the flow I have for these 4 screens, main, option 1, option 2, option 3, then return to main.
Thanks for your time!
>Solution :
The error message you’re seeing is saying that category is undefined when you’re trying to access it using _useRoute$params.category. This error could be caused by a few different things, but one possibility is that the category parameter is not being passed correctly from one of the screens to the main page.
One thing to double-check is that the category parameter is being passed correctly when you navigate from the option screens back to the main page. One way to do this is to use the navigation.navigate function to pass the category parameter as a second argument, like this:
navigation.navigate('Main', { category: category });
Then in the main page, you can access the category parameter like this:
const { params } = useRoute();
const category = params?.category;
It’s also possible that the error is caused by a typo or other mistake in your code, so it’s always a good idea to review your code carefully and double-check that everything is spelled correctly and that you’re using the correct variable names.