Platform: React Native (Expo)
I want to get my params to a new screen using class-based components and React Navigation 6.0.
This is how I am sending the params:
this.props.navigation.navigate("BlogDetails", { blogID: item.ID });
and this is how I’m retrieving it:
componentDidMount() {
const { blogID } = this.props.route.params;
this.setState({ blobID: blogID });
console.log(this.state.blobID);
}
There are no errors, however, the console.log()
returns ""
.
I am unable to find where I’m going wrong but I’m pretty sure the problem is somewhere during the retrieval, I’m pretty confident that the data is being sent to the screen.
3
Answers
state doesn’t update immediately, if you want use state after update should act like this
It seems different for react navigation version.
or
try to use getParam function.