Last active
September 28, 2018 09:35
-
-
Save jpgorman/469ee033c21d3c9b8a11a5b641798d94 to your computer and use it in GitHub Desktop.
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
export class LazyLoadModule extends React.component { | |
... | |
async componentDidMount() { | |
... | |
const { resolve } = this.props; | |
const { default: module } = await resolve(); | |
const { name, reducers } = module; | |
const { store } = this.context; | |
if (name && store && reducers) | |
store.registerDynamicModule({ name, reducers }); | |
this.setState({ module }); | |
} | |
... | |
componentWillUnmount() { | |
const { module } = this.state; | |
const { store } = this.context; | |
const { name } = module; | |
if (store && name) store.unRegisterDynamicModule(name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment