admin管理员组文章数量:1323029
The heart of my problem is that when I have this in my navigationOptions:
static navigationOptions = ({ navigation }) => {
console.log(navigation)
console.log(navigation.state)
}
The first 'console.log' statement returns the navigation object plete with "navigation.state.params" containing the params that I have passed into it.
However, the second 'console.log' returns the 'navigation.state' object but for some reason the 'params' are undefined.
Here is how I am setting the navigation params (from redux):
function mapStateToProps(state, props) {
let sum = 0
for (let product in state.cart) {
sum += state.cart[product]
}
return props.navigation.state = {params: {cartSum: sum}}
}
And my developer environment:
node 6.10.1
react-native 0.46.4
redux 3.7.1
react-redux 5.0.5
react-navigation 1.0.0-beta.11
The heart of my problem is that when I have this in my navigationOptions:
static navigationOptions = ({ navigation }) => {
console.log(navigation)
console.log(navigation.state)
}
The first 'console.log' statement returns the navigation object plete with "navigation.state.params" containing the params that I have passed into it.
However, the second 'console.log' returns the 'navigation.state' object but for some reason the 'params' are undefined.
Here is how I am setting the navigation params (from redux):
function mapStateToProps(state, props) {
let sum = 0
for (let product in state.cart) {
sum += state.cart[product]
}
return props.navigation.state = {params: {cartSum: sum}}
}
And my developer environment:
node 6.10.1
react-native 0.46.4
redux 3.7.1
react-redux 5.0.5
react-navigation 1.0.0-beta.11
2 Answers
Reset to default 6Used like this
static navigationOptions = ({ navigation }) => {
const { params = {} } = navigation.state;
console.log(params)**will show you the handlesave with object value hello**
};
this.props.navigation.setParams({ handleSave: "Heloo" });
May be this can help you , Thanks
It is possible to go around this issue by implementing a method in the ponent class.
getNavigationParams() {
return this.props.navigation.state.params || {};
}
This will give you access to the parameters. But it does not work for nested objects.
本文标签:
版权声明:本文标题:javascript - React Navigation: 'navigation.state.params' is always undefined in 'static navigationOption 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742109980a2421200.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论