I'm trying to make a thunk that filters a base array and passes data into the filtered array, but I keep getting an error when I do a dispatch in useEffect.
Writes: "Argument of type '(dispatch: ThunkDispatch<IRootState, void, Action>, getState: IRootState) => void' is not assignable to parameter of type 'AnyAction'."
I don't understand what to do, I followed the redux documentation, but still nothing works
Thunk action-creator:
export const filterServices = () => {
return (
dispatch: ThunkDispatch<IRootState, void, Action>,
getState: IRootState
) => {
const category = getState.filters.category;
const subcategory = getState.filters.subcategory;
let result = getState.services.services;
result =
category === 'All categories'
? result
: result.map((e: any) => e.category === category);
result =
subcategory === 'All Subcategories'
? result
: result.map((e: any) => e.subcategory === subcategory);
dispatch(getfilteringServices(result));
};
};
Action interfaces
export interface IFilteringServices {
type: ActionType.FILTERING_SERVICES;
payload: IService[];
}
export type Action =
| IGetServices
| IAddToCart
| IRemoveFromCart
| IFilteringServices
| IUseFilters;
RootState interface:
export type IRootState = typeof storeState;
dispatch
useEffect(() => {
dispatch(filterServices());
}, []);