【问题标题】:Rematch Loading Typescript keep getting Reducer "loading" returned undefined during initialization重新匹配加载 Typescript 在初始化期间不断收到减速器“加载”返回未定义
【发布时间】:2020-04-01 11:11:41
【问题描述】:

我正在为我的 redux 使用 @rematch/core 和 @rematch/loading。

目前面临一些问题。当我放置加载插件时,请继续返回我Reducer "loading" returned undefined during initialization.

import {
    init, RematchDispatch, RematchRootState,
} from '@rematch/core';
import { createBrowserHistory } from 'history';
import { connectRouter } from 'connected-react-router';
import loading from '@rematch/loading';
import { models, RootModel } from './models';

const history = createBrowserHistory();
const loadingPlugin = loading({});

const rootReducer = () => ({
    router: connectRouter(history),
});

export const store = init({
    models,
    plugins: [loadingPlugin],
    redux: {
        reducers: rootReducer(),
    },
});


export type Store = typeof store;
export type RootDispatch = RematchDispatch<RootModel>;
export type RootState = RematchRootState<RootModel>;

有什么办法吗?

谢谢。

【问题讨论】:

    标签: reactjs typescript redux rematch


    【解决方案1】:

    由于 Rematch 版本 v2.x.x 您可以获得完全类型化的插件,这里是一个获取类型化加载插件的示例:

    import loadingPlugin, { ExtraModelsFromLoading } from '@rematch/loading'
    import { init, RematchDispatch, RematchRootState } from '@rematch/core'
    import { models, RootModel } from './models'
    
    type FullModel =  ExtraModelsFromLoading<RootModel>
    
    export const store = init<RootModel, FullModel>({
        models,
          plugins: [loadingPlugin()],
    })
    

    @rematch/updated 的工作方式与此相同,您可以在新的文档站点上查看更多信息:https://rematchjs.org/docs/plugins/loading/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-18
      • 1970-01-01
      • 2012-06-18
      • 1970-01-01
      • 2022-01-06
      • 2023-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多