首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >此表达式不可调用。类型'Thunk<Collections,undefined,any,{},any>‘没有调用签名

此表达式不可调用。类型'Thunk<Collections,undefined,any,{},any>‘没有调用签名
EN

Stack Overflow用户
提问于 2020-12-10 13:42:23
回答 1查看 184关注 0票数 1

这是我的代码。我想调用action,但上面的错误一直在发生。

代码语言:javascript
复制
const action = useStoreActions( (actions : StoreModel) => actions.collections.fetchCollections);

useEffect( () => {
    action()
},[])

这是我的集合对象,我想访问fetchCollections。这是任何简单的react状态管理代码。附言:这里我删除了fetchCollectionsRequest,fetchCollectionsSuccess,fetchCollectionsFailure。

代码语言:javascript
复制
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

代码语言:javascript
复制
import { collectionsModel, Collections } from './collectionsModel';

export interface StoreModel {
    collections : Collections;;
}

export const model = {
    collections : collectionsModel,
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-27 01:49:24

这是因为您正在键入useStoreActions挂钩的actions参数(该参数并不直接符合正确的类型)。

相反,请使用typed hooks

代码语言:javascript
复制
// outside the component
import { createTypedHooks } from 'easy-peasy';

const { useStoreActions } = createTypedHooks<StoreModel>();

// inside the component:
const { fetchCollections } = useStoreActions(actions => actions.collections);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65229104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档