Answer the question
In order to leave comments, you need to log in
How to rewrite action in a component?
Good afternoon!
There is a connection of the form
@connect(null, dispatch => ({
handleFilters: (type, text) => dispatch(handleFilters(type, text))
}))
export const handleFilters = (type, val) => {
switch (type) {
case "input":
return {
type: FILTER_BY_INPUT,
payload: val
};
case "time":
return {
type: FILTER_BY_TIME,
payload: val
};
case "hall":
return {
type: FILTER_BY_HALL,
payload: val
};
case "status":
return {
type: FILTER_BY_STATUS,
payload: val
};
case "dateFrom":
return {
type: FILTER_BY_DATE_FROM,
payload: val
};
case "dateTo":
return {
type: FILTER_BY_DATE_TO,
payload: val
};
}
};
Answer the question
In order to leave comments, you need to log in
Would you like to understand why this transfer?
However, if you want to use dispatch inside your actions, you can use the redux-thunk middleware , then you can write:
export const handleFilters = (type, val) => {
return (dispatch, getState) => {
switch (type) {
case "input":
dispatch({
type: FILTER_BY_INPUT,
payload: val
});
case "time":
...
}
}
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question