我在使用 redux 的方式 react native 导航时遇到了这个问题。
Listserviceaction.js
包含正在导入的 webservicecall 组件 从 '../components/ListComponent' 导入 ListComponent;
Listactiontype.js
包含操作ActionTypes 导出 const SERVICE_PENDING = 'service_pending' 等
列表组件.js
组件,在列表等上呈现数据
reducer
然后是 reducer 部分
场景/List.js
存储绑定(bind)将在应用程序的初始点内完成,并传递到其他应用程序组件,如下所示。
import React, { Component } from 'react';
import { Provider } from 'react-redux';
import store from '../reducers/index';
import ServiceAction from '../actions/listserviceaction';
import { Container, Content, Picker, Button, Text } from "native-base";
export default class RenderList extends Component {
render() {
return (
<Provider store={store}>
<ServiceAction />
</Provider>
);
}
}
现在,在加载组件之后,当我单击我的 onPress={() => this.props.navigation.navigate("ProfileScreen")} 时 listcomponent 它会引发错误(未定义不是对象.. this.props.navigation.navigate)有什么问题吗?有更好的解决方案吗? 谢谢。
最佳答案
在您的 ServiceAction 中包含 this.props.navigation
,如下所示:
<ServiceAction navigation={this.props.navigation}/>
因为props.navigation
默认位于您的父组件上
在 ServiceAction 组件上,您将访问导航,例如:
..
goToSignUp() {
this.props.navigation.navigate('SignUp');
}
..
对于我来说,之前也很困惑。干杯!
关于javascript - React Native 导航(未定义不是一个对象.. this.props.navigation.navigate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53844308/