createReducer(initialState, mainAction, {
actionName: reducerHelper
})
???const createQuestionUpdate = (state, action) => {
switch (action.type) {
case `${CREATE_QUESTION}_UPDATE`:
const {data, path } = action.payload;
const res = set(state, path, data);
return Object.assign({}, res);
default:
return state;
}
};
export default createReducer(Object.assign({}, InitialState), CREATE_QUESTION, {
[`${CREATE_QUESTION}_UPDATE`] : createQuestionUpdate
});
export const onChange = (e, val = "value") => dispatch => {
let type = e.target.name; //actionType
let property = e.target.id;
let value = e.target[val]; // input value
let { errors } = validate[type]({ [property]: value }); // error object for all related inputs
dispatch([
{
type: type,
payload: { [property]: value }
},
{
type: `${type}_ERROR`,
payload: {
errors: { [property]: get(errors, property) }
}
}
]);
};