Last active
July 4, 2022 14:50
-
-
Save koss-lebedev/95fb014439d787059f94e53e1dd8d69e to your computer and use it in GitHub Desktop.
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
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