Created
May 9, 2019 19:45
-
-
Save francajosejunior/fc25cf16f8178b5dc76ce26b7d6d845a to your computer and use it in GitHub Desktop.
Auto load all reducers with require.context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { combineReducers } from 'redux'; | |
import { reducer as formReducer } from 'redux-form'; | |
const modules = {} | |
const context = require.context('./', true, /reducer\.js$/) // carrega reducers de todos os componentes | |
context.keys().forEach((filename) => { | |
const arr = filename.split('/') | |
const key = arr[arr.length - 2] | |
const ctx = context(filename) | |
if (ctx.default) { | |
modules[key] = ctx.default | |
} | |
}) | |
export default combineReducers({ ...modules, form: formReducer }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment