I have 2 Screens im trying to pass parameters between. HomeScreen is the previous screen in this case.
function HomeScreen(props: {
//some props
route:any,
navigation:any,
}) {
React.useEffect(() => {
if (props.route.params?.defined) {
console.log(props.route.params?.defined);
}
}, ); //rest of the code
Second component
function SavedRoutesScreen(props: { navigation: any }) {
function handleGo() {
props.navigation.navigate({
name: "Home",
params: { defined: true },
});
} //rest of the code
Basically im trying to pass parameters from SavedRoutesScreen to HomeScreen but I get this error. : "TypeError: undefined is not an object (evaluating ‘props.route.params’)"
anyone know whats up with this?
2
Answers
I think you should use
navigation
prop object instead ofroute
.If that does not work, you should try using
.getParams
https://www.javatpoint.com/react-native-passing-value-between-screenYou need to pass two arguments to the navigation.navigate() method. I have seen that you are passing an object which is not correct.
navigation.navigate(name, params)
name – A destination name of the route that has been defined somewhere
params – Params to pass to the destination route.
Try this: