这是我的代码。我想采取行动,上述错误不断出现。
const action = useStoreActions( (actions : StoreModel) => actions.collections.fetchCollections);
useEffect( () => {
action()
},[])
这是我的集合对象,我想访问 fetchCollections。这是任何简单的反应状态管理代码。PS:这里我删除了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));
}),
}
这是我的model.tsx
import { collectionsModel, Collections } from './collectionsModel';
export interface StoreModel {
collections : Collections;;
}
export const model = {
collections : collectionsModel,
}