【发布时间】:2020-03-09 12:16:13
【问题描述】:
因为我刚刚在我的 react native 项目中实现了 Redux,所以我创建了我的第一个 reducer、action 和 store,但是它不起作用。
componentDidMount
this.props.getUser(user());
console.log('Props: ', this.props);
console.log:
Props: {screenProps: undefined, navigation: {…}}
调度员
const mapDispatchToProps = (dispatch) => {
return ({
getUser: (data) => dispatch(data)
})
}
export default connect(mapStateToProps, mapDispatchToProps)(homeNav);
用户功能
export function user () {
return dispatch => {
console.log(21312312);
dispatch(request({}))
}
function request (user) {
return { type: GET_USER_REQUEST, user }
}
function success (user) {
return { type: GET_USER_SUCCESS, user }
}
function failure (error) {
return { type: GET_USER_FAILURE, error }
}
}
请查看下面的截图来查看 homeNav 是如何导入的
【问题讨论】:
-
你是如何导入
homeNav组件的? -
@FernandoMontoya 能否请您查看问题末尾的屏幕截图?
-
你可以在
createStackNavigator之前尝试连接Redux -
我刚刚尝试将 mapStateToProps 和 mapDispatchToProps 放在 createStackNavigator 之前,但连接线仍然放在最后。因为 homeNav 不会在功能之前无法访问,它仍然无法正常工作
标签: reactjs react-native redux react-redux