그래서 사용자 감속기 생성 : 다음과 같이 생성됩니다돌아 오는 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'과 같은 액션 크리에이터 중 한 명을 호출하는 경우 코드 –
을 codeandbox.io – Deano