Here is my code. I want to call action and above error is keep coming.
const action = useStoreActions( (actions : StoreModel) => actions.collections.fetchCollections);
useEffect( () => {
action()
},[])
This is my collections object and I wants to access fetchCollections. This is any easy-peasy react state management code. P.S: Here I removed fetchCollectionsRequest, fetchCollectionsSuccess, fetchCollectionsFailure.
import { Action, action, thunk, Thunk } from 'easy-peasy';
export interface Collections {
isLoading : boolean;
collections : any[];
error : string;
fetchCollections : Thunk<Collections>;
}
export const collectionsModel : Collections = {
isLoading : false,
collections : [],
error : '',
fetchCollections : thunk( actions => {
actions.fetchCollectionsRequest();
axios.get('/categories?filter={"where":{"isHidden":false}}')
.then( res => actions.fetchCollectionsSuccess(res.data))
.catch( err => actions.fetchCollectionsFailure(err.message));
}),
}
And this is my model.tsx
import { collectionsModel, Collections } from './collectionsModel';
export interface StoreModel {
collections : Collections;;
}
export const model = {
collections : collectionsModel,
}
This is because you are typing the
actions
parameter of theuseStoreActions
hook (which does not directly conform to the correct types).Instead, use typed hooks: