Last active
August 27, 2017 13:30
-
-
Save erasmo-marin/9e614f5f37757ec38532b2b9eb323757 to your computer and use it in GitHub Desktop.
Switch with registry container
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
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