I am getting an error while accessing parameter by the getParam method like following .
const source = this.props.navigation.getParam("source","0")
const doFollow = this.props.navigation.getParam("doFollow","")
I have passed the parameter using the following method
this.props.navigation.navigate('Details', {otherParam:"anything"})
I am getting an error while accessing parameter by the getParam method like following .
const source = this.props.navigation.getParam("source","0")
const doFollow = this.props.navigation.getParam("doFollow","")
I have passed the parameter using the following method
this.props.navigation.navigate('Details', {otherParam:"anything"})
Share
Improve this question
edited Apr 9, 2020 at 18:15
Raghu
asked Apr 9, 2020 at 17:15
RaghuRaghu
1251 gold badge2 silver badges7 bronze badges
1
- 2 Can you add some more details please ? – Dipansh Khandelwal Commented Apr 9, 2020 at 17:31
6 Answers
Reset to default 11It depends on your react-navigation
version that you are using.
In v4
this.props.navigation.getParam('source')
In v5
this.props.route.params.source
It may not fit your example pletely but i'm passing/retrieving data like this:
this.props.navigation.navigate('DisplayPage', { meetId: item.ID })
Then on receiving page
props.navigation.state.params.meetId
If You are using the latest version of react navigation(i.e. Version 5.0 or more). You can simply use this.props.route.params.YOUR_PARAMETER_KEY
for passing parameters
If you want to send data(ex. JSON) from one class to another in React-Native.
this.props.navigation.navigate('Detail Screen', json)
Here json is the JSON object with key-value. Ex.
{ id: 1234, name: "Dean", age: 30}
In the receiver class/ Navigated Class in render
const name = this.props.route.params.name;
const age = this.props.route.params.age;
NOTE:Please make sure data is send as key value {key: value}
Assuming that you are using the latest react-navigation
.
You are making a small mistake.
Try removing the second parameter from the function.
let source = this.props.navigation.getParam("source")
let doFollow = this.props.navigation.getParam("doFollow")
if(!source) source = "0"
if(!doFollow) doFollow = ""
props.navigation.getParams(**source**) is not working in V4
props.route.params.**source** in at V5
V5:
without object destructuring -->
function(props)
{
props.navigation.goBack() //For navigation
props.route.params.**source** //For params
}
with object destructuring -->
function({navigation, route})
{
navigation.goBack() //FOR navigation
route.params.**source** //FOR params
}