import React from 'react'; const ComponentA = () => <h1>Component A</h1>; const ComponentB = () => <h2>Component B</h2>; const componentMap = { a: ComponentA, b: ComponentB, }; const MyComponent = ({ type }) => { const ComponentToRender = componentMap[type]; return <ComponentToRender />; }; export default MyComponent;
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter