Skip to content

Instantly share code, notes, and snippets.

@rileybracken
Created November 5, 2021 21:11
Show Gist options
  • Save rileybracken/af414d27f765946fb1b5d497cc5dbdb7 to your computer and use it in GitHub Desktop.
Save rileybracken/af414d27f765946fb1b5d497cc5dbdb7 to your computer and use it in GitHub Desktop.
import React from 'react';
export interface DynamicComponentProps {
_componentTypes: Record<string, any>;
name: string;
[key: string]: any;
}
const DynamicComponent = ({
_componentTypes,
name,
...props
}: DynamicComponentProps) => {
if (_componentTypes && name) {
const Component = _componentTypes[name];
return Component ? <Component {...props} /> : null;
}
return null;
};
export default DynamicComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment