Skip to content

Predefined store that can help you throughout your redux project

License

Notifications You must be signed in to change notification settings

hajjiTarik/redux-store

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 

Repository files navigation

alt tag

Redux Custom Store

Redux custom store is a redux store with additional features (redux-saga, devTools)...

Usage :

Add class Store :

import ConfigureStore from './path/to/ConfigureStore';

Instanciate the store with params :

The store takes an initial state and a sagas list, and it fork all sagas passed in parametre.

PS : Normally we must pass to the store only the sagas of initialisations, if one has sagas specific to a domain is better passed by an HOC saga, here an example in the same repository Redux SAGA HOC

const preloadState = {
  // initial state
};
const sagas = [initSaga_1, initSaga_2]; // initial sagas
const store = new ConfigureStore({preloadState , sagas});

SSR :

For Server Side rendering you can use initActions :

function indexClient(context) {
  return new Promise((resolve, reject) => {
    try {
      config.update(context.config);
      const appComponent = require('../app/appComponent').default;
      
      const sagas = [initSaga_1, initSaga_2]; // will run in SSR
      const actions = [initAction_1(), init_Action2_() ...];
      const store = new Store(sagas);

      store.initActions(actions).then (() => {
         const element = (
            <Provider store={store}>
              <appComponent />
            </Provider>
          )
          resolve({
            element,
            state: store.getSate(),
          });
          
      }).catch((err) => {
        reject(err);
      });
    } catch (err) {
      reject(err);
    }
  });
}

Licence

MIT

Releases

No releases published

Packages

No packages published