Skip to content

Instantly share code, notes, and snippets.

@eric-burel
Last active September 18, 2018 07:22
Show Gist options
  • Save eric-burel/3ddd0186734c4f5f8aae0c2ec7cc89e9 to your computer and use it in GitHub Desktop.
Save eric-burel/3ddd0186734c4f5f8aae0c2ec7cc89e9 to your computer and use it in GitHub Desktop.
// Package 1 - "my-basic-ui"
const MyBasicButton = ({onClick, children}) => (
<button onClick={onClick}>
{children}
</button>
)
// Tell other packages they can use your component
// under the name "Button"
registerComponent({
name: 'Button',
component: MyBasicButton
})
// Package 2 - "my-better-ui"
// We replace the Button component to improve it
const MyStyledButton = ({onClick, children}) => (
<button className="btn" onClick={onClick}>
{children}
</button>
)
replaceComponent({
name:'Button',
component: MyStyledButton
})
// Package 3 - "my-app"
// Example usage. Thanks to registration, we can change the Button style
// without touching this code at all
const MyInterface = () => (
<Components.Button onClick={() => console.log('click')}>
Click Me!
</Components.Button>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment