I am sending an object as params. But when I try to access the params in another screen. It says undefined.
Screen 1:
<TouchableOpacity
onPress={() => {
navigation.navigate('DraggableList', {
routes: ['A', 'B', 'C'],
name: 'ABCD',
});
}}
</TouchableOpacity>
Screen 2:
console.log('Props==============>', props.route.params);
Output:
But when I try to access the variables of the object:
Screen 2:
console.log('Props==============>', props.route.params.name);
2
Answers
I actually just added a '?' like this,
And it worked! Turns out there is a slight delay for variables to reach the component and my component was accessing it before it was available.
as you can see props ====> ABCD, it already logged params.name
and I think the problem is with type-checking,
params have no type
try this: