Dynamic redux
With dynamic redux you can inject your reducers on the fly
Installation
nikandlv@nikandlv.ir:~$ npm install redux react-redux redux-thunk
Then simply copy Data
folder into your project
Setup
Import it
import ReduxProvider from './Data/ReduxProvider'
Wrap your root component or any base component
ReactDOM.render(
<ReduxProvider>
<Application />
</ReduxProvider>, document.getElementById('root'));
Injecting a reducer
Import the store and a reducer
import CounterReducer from './Data/Reducers/CounterReducer'
import Store from './Data/Store'
Inject your reducer
Store.injectReducer('CounterReducer',CounterReducer)
injectReducer
takes two parameters a key
and the reducer
Use withDynamic
builder
using withDynamic
builder you can easily access your reducers
and actions
in your components
import withDynamic from './Data/withDynamic';
export default withDynamic(MyComponent)
.injectAction('name', func)
.injectReducer('CounterReducer')
.build()
there are 2 main functions
injectAction
which takes function name and the action and injects it into your component props
injectReducer
which takes a reducer name and injcets it into your component props