Skip to content

Instantly share code, notes, and snippets.

@dance2die
Created October 28, 2018 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dance2die/4c18f793f5153a75a7770efe6c3ad31e to your computer and use it in GitHub Desktop.
Save dance2die/4c18f793f5153a75a7770efe6c3ad31e to your computer and use it in GitHub Desktop.
addView = async viewName => {
const { loadedComponents } = this.state;
if (loadedComponents[viewName]) return;
const View = Views[viewName];
const key = shortid.generate();
const { data } = this.props;
const component = View ? (
<View key={key} data={data} />
) : (
<Views.NullView key={key} />
);
this.setState(prevState => ({
components: [...prevState.components, component],
loadedComponents: { ...prevState.loadedComponents, [viewName]: true }
}));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment