Skip to content

Instantly share code, notes, and snippets.

@koss-lebedev
Last active July 4, 2022 14:50
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 koss-lebedev/95fb014439d787059f94e53e1dd8d69e to your computer and use it in GitHub Desktop.
Save koss-lebedev/95fb014439d787059f94e53e1dd8d69e to your computer and use it in GitHub Desktop.
const knownTypes = {}
export const messageFactory = {
registerType: (type, Component) => knownTypes[type] = Component,
render: (message) => {
const Component = knownTypes[message.type]
if (!Component) {
throw new Error('Unknown message type')
}
return <Component message={message} />
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment