Skip to content

Instantly share code, notes, and snippets.

@erasmo-marin
Last active August 27, 2017 13:30
Show Gist options
  • Save erasmo-marin/9e614f5f37757ec38532b2b9eb323757 to your computer and use it in GitHub Desktop.
Save erasmo-marin/9e614f5f37757ec38532b2b9eb323757 to your computer and use it in GitHub Desktop.
Switch with registry container
import React from "react";
import withRegistry from "./withRegistry";
//here we are using decorators
//an alternative is using it just as a function (withRegistry(Switch))
@withRegistry
class Switch extends React.Component {
render () => {
let {registry, type, …rest} = this.props;
const Component = registry.getComponent(type);
return <Component {…rest}/>;
}
}
export default Switch;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment