我想在我的注册页面中使用终极版,所以我创建了一个用户减速器:终极版mapStateToProps连接不正确
const user = (state = initialState, action) => {
switch (action.type) {
case 'TYPE_FIRSTNAME':
console.log('typed first name ' + action.text);
return { ...state, firstName: action.text };
case 'TYPE_LASTNAME':
return { ...state, lastName: action.text };
case 'TYPE_EMAIL':
return { ...state, email: action.text };
case 'TYPE_PASSWORD':
return { ...state, password: action.text };
default:
return state;
}
}
它创建这样的:
const AppReducer = combineReducers({
nav,
user
});
export default AppReducer;
的导航减速是对于导航(与反应导航一起使用,它工作正常)。之后,我创建了一个容器:
const mapStateToProps = state => {
return {
firstName: state.firstName,
lastName: state.lastName,
}
};
const mapDispatchToProps = (dispatch, ownProps) => ({
typeFirstName: (text) => {console.log('typed firstname');
dispatch({type: 'TYPE_FIRSTNAME', text})},
typeLastName: (text) => dispatch({type: 'TYPE_LASTNAME', text}),
registerUser:() => {
//register("mamad");
console.log('called register user : ');
dispatch({type: 'MAINSCREEN'})
}
});
export default connect(mapStateToProps,
mapDispatchToProps)(RegisterScene)
但它从来没有被调用,为什么?
你是说如果你把一个调试器放在''mapStateToProps'中的'return {'行中,它永远不会被命中? –
什么都不叫?如果你打电话给类似'typeFirstName'的动作创作者,请告诉我们你可以将代码 –
添加到codesandbox.io – Deano