Skip to content

Instantly share code, notes, and snippets.

@jpgorman
Last active September 28, 2018 09:35
Show Gist options
  • Save jpgorman/469ee033c21d3c9b8a11a5b641798d94 to your computer and use it in GitHub Desktop.
Save jpgorman/469ee033c21d3c9b8a11a5b641798d94 to your computer and use it in GitHub Desktop.
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