0

我正在为我的 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>;

有什么解决办法吗?

谢谢。

4

1 回答 1

1

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

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/

于 2021-04-05T09:48:34.543 回答