Last active
April 15, 2019 11:12
-
-
Save wanmigs/60667386a6a6a7ca41018c9967938d6f to your computer and use it in GitHub Desktop.
React Native Dynamic Exports
This file contains 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
const requireContext = require.context('./', false, /.*\.(js)$/) | |
let components = {}; | |
requireContext.keys().forEach(fileName => { | |
if (fileName === './index.js') return | |
let name = fileName.replace(/(\.\/|\.js)/g, '') | |
components[name] = requireContext(fileName).default | |
}) | |
module.exports = components |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
export base components under the same folder?
instead of importing it like this
You can do it like this: