Skip to content

StanislavZab/asyncReducerManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The library is designed to help you create asynchronous reduxers for the Redux store.
The library also contains a React component for easy addition and removal of editors.


###Example:

import { CombinedState, configureStore, Reducer, ReducersMapObject } from '@reduxjs/toolkit';
import { createReducerManager, ReduxStoreWithManager } from 'async-reducer-manager';

export function createReduxStore<StateSchema>(rootReducers: ReducersMapObject<StateSchema>) {
    const reducerManager = createReducerManager<StateSchema>(rootReducers);

    const store = configureStore({
        reducer: reducerManager.reduce as Reducer<CombinedState<StateSchema>>,
        devTools: __IS_DEV__,
    }) as ReduxStoreWithManager<StateSchema>;

    store.reducerManager = reducerManager;

    return store;
}
import { DynamicModuleLoader } from 'async-reducer-manager';

interface IProps {
    Your props...
}

const initialReducers: ReducersList<StateSchema> = {
    Your reducer...
};

export const ComponentName = (props: IProps) => {
    Component logic...

    return (
        <DynamicModuleLoader reducers={initialReducers} removeAfterUnmount>
            Your components
        </DynamicModuleLoader>
    );
}

DynamicModuleLoader accepts two parameters as passes:

  • redusers - list of reducers to add to the store.
  • removeAfterUnmount - flag indicating whether to leave the added reducers in the store after unmounting the component or delete (true - delete).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published