在我的组件中,我解雇了我的行动:
submitForm(e) {
const language = e.target.value;
this.props.actions.addLanguage(language, 'language', '2');
}
并连接到redux:
const mapStateToProps = state => ({
UserDetails: state.UserDetails,
});
const mapDispatchToProps = dispatch => ({
actions: bindActionCreators(UserActions, dispatch),
});
export default connect(mapStateToProps, mapDispatchToProps)(Screen1);
操作/索引:
import * as types from '../constants/ActionTypes';
export const addDetails = (age, gender, ethnicity) => ({
type: types.ADD_DETAILS,
age,
gender,
ethnicity,
});
export const addLanguage = (value, language, page) => ({
type: types.ADD_LANGUAGE,
value,
language,
page,
});
export const addAccessCode = (value, field) => ({
type: types.ADD_ACCESSCODE,
value,
field,
});
的UserDetails:
import {
ADD_DETAILS,
ADD_ACCESSCODE,
ADD_LANGUAGE,
ADD_DRINKS,
} from '../constants/ActionTypes';
const initialState = {
id: 0,
language: '',
session: '',
values: '',
accessCode: '',
age: 0,
gender: '',
ethnicity: '',
drinkOften: '',
drinkConcern: '',
};
export default function UserDetails(state = initialState, action) {
debugger;
return (dispatch, state) => {
switch (action.type) {
case ADD_LANGUAGE:
this.props.router.push(`${action.page}`);
return {
...state,
[action.field]: action.value,
};
case ADD_ACCESSCODE:
return {
...state,
[action.field]: action.value,
};
case ADD_DETAILS:
return {
...state,
ethnicity: action.ethnicity,
gender: action.gender,
age: action.age,
};
case ADD_DRINKS:
return {
...state,
[action.field]: action.value,
};
default:
return state;
}
};
}
有什么想法吗?
@Ravindra Ranwala我可以用你的建议来解决这个问题,但是在减速器中它还没有定义,有什么想法吗?
使用我的调试器,操作实际上正在进行,但我的reducer无法通过thunk return (dispatch, getState) => {
答案 0 :(得分:0)
将return语句添加到您的操作中。这将解决您的问题。就像这样。
export const toggleTodo = id => {
return {
type: 'TOGGLE_TODO',
id
}
}
希望这会有所帮助。快乐的编码!
答案 1 :(得分:0)
删除fs/proc/array.c:do_task_stat()
,您只需要在reducer中切换语句。以下是您的reducer应如何从redux文档中获取的示例。
KSTK_EIP(task)