redux#PreloadedState TypeScript Examples

The following examples show how to use redux#PreloadedState. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: handlePlugin.ts    From reactant with MIT License 7 votes vote down vote up
handlePlugin: HandlePlugin = (
  service: any,
  pluginHooks: PluginHooks
) => {
  if (service instanceof PluginModule) {
    if (typeof service.beforeCombineRootReducers === 'function') {
      pluginHooks.beforeCombineRootReducers.push(
        (reducers: ReducersMapObject) =>
          service.beforeCombineRootReducers!(reducers)
      );
    }
    if (typeof service.afterCombineRootReducers === 'function') {
      pluginHooks.afterCombineRootReducers.push((rootReducer: Reducer) =>
        service.afterCombineRootReducers!(rootReducer)
      );
    }
    if (typeof service.preloadedStateHandler === 'function') {
      pluginHooks.preloadedStateHandler.push(
        (preloadedState: PreloadedState<any>) =>
          service.preloadedStateHandler!(preloadedState)
      );
    }
    if (typeof service.enhancer === 'function') {
      pluginHooks.enhancer.push(service.enhancer.bind(service));
    }
    if (typeof service.middleware === 'function') {
      pluginHooks.middleware.push(service.middleware.bind(service));
    }
    if (typeof service.afterCreateStore === 'function') {
      pluginHooks.afterCreateStore.push(service.afterCreateStore.bind(service));
    }
    if (typeof service.provider === 'function') {
      pluginHooks.provider.push(service.provider.bind(service));
    }
  }
}
Example #2
Source File: index.tsx    From nouns-monorepo with GNU General Public License v3.0 6 votes vote down vote up
export default function configureStore(preloadedState: PreloadedState<any>) {
  const store = createStore(
    createRootReducer(history), // root reducer with router state
    preloadedState,
    composeWithDevTools(
      applyMiddleware(
        routerMiddleware(history), // for dispatching history actions
        // ... other middlewares ...
      ),
    ),
  );

  return store;
}
Example #3
Source File: index.tsx    From pybricks-code with MIT License 6 votes vote down vote up
testRender = (
    component: ReactElement,
    state?: PreloadedState<RootState>,
): [UserEvent, RenderResult, jest.SpyInstance<AnyAction, [action: AnyAction]>] => {
    const user = userEvent.setup();
    const store = createStore(rootReducer, state);
    const dispatch = jest.spyOn(store, 'dispatch');

    const i18n = new I18nManager({ locale: 'en' });

    const result = render(
        <Provider store={store}>
            <I18nContext.Provider value={i18n}>
                <HotkeysProvider>{component}</HotkeysProvider>
            </I18nContext.Provider>
        </Provider>,
    );

    return [user, result, dispatch];
}
Example #4
Source File: index.ts    From multisig-react with MIT License 5 votes vote down vote up
aNewStore = (localState?: PreloadedState<unknown>): Store =>
  createStore(reducers, localState, finalCreateStore)
Example #5
Source File: plugin.ts    From reactant with MIT License 5 votes vote down vote up
/** preloaded state handler for Redux */
  preloadedStateHandler?(
    preloadedState: PreloadedState<any>
  ): PreloadedState<any>;