react-painless-redux
v0.0.5
Published
Use painless-redux with react hooks
Downloads
5
Maintainers
Readme
react-painless-redux
Description
This is painless-redux adapter for React using @reduxjs/toolkit.
Install:
npm i painless-redux react-painless-redux @reduxjs/toolkit
import { createPainlessRedux } from 'react-painless-redux'; // When you don't have any redux store yet. If you have - adapt it const subRootReducer = (state = {}) => state; const rootReducer = combineReducers({ subRoot: subRootReducer, }); const redux = configureStore({ reducer: rootReducer, devTools: true, }); const addReducer = (key: string, reducer: Reducer) => { const newReducer = combineReducers({ subRoot: subRootReducer, [key]: reducer }); redux.replaceReducer(newReducer); }; const { StoreContext, useStore, STORE, } = createPainlessRedux(redux, addReducer); const App: React.FC = () => { return ( <StoreContext.Provider value={STORE}> // your app </StoreContext.Provider> ) }
Usage
import { useEntity } from 'react-painless-redux';
import { YourEntityInterface } from './serviceSpecifications.types';
export const useYourEntity = () => useEntity<YourEntityInterface>({
name: 'your-entity-name',
});