Quiero usar un componente pasado de los accesorios para envolver niños, si está definido.
interface ExampleProps { wrapper: JSX.Element; } function Example({ wrapper }: ExampleProps) { return ( // Wrap this with `wrapper`, only if it is defined, else don't wrap. <Child></Child> ) }¿Cómo se puede hacer esto?
Puedes hacerlo de esta manera
function Example({ wrapper }) { if(wrapper) { const Wrapper = wrapper //to make it alike component return <Wrapper><Child></Child></Wrapper> } return ( <Child></Child> ) }Probar:
function Example({ wrapper, children }) { const Wrapper = wrapper || React.Fragment; // custom components should start with capital letter return ( <Wrapper> {children} </Wrapper> ) }