I have a Button component that accepts anything as a child. However, anytime an Icon component is passed into that Button I need a bit more control of the styling and need to wrap it inside of another div while also returning any other text, elements, or anything else that might be rendering alongside that Icon.
const Button = ({
display,
children,
...other
}) => {
return (
<div
display={display}
{...other}
>
{children}
</div>
);
};
So if I’m using this component, I’d use it like this:
<Button>
Here’s some text <Icon name=“smile” /> ...and more text after the icon
</Button>
And expect the HTML output to look like this:
<button>
Here’s some text <div class=“AN-EXTRA-DIV-WRAP”><svg id=“smile”>…</svg></div> ...and more text after the icon
</button>
How can I pull only the icon out and make the necessary transformations and return it in the same source order that was originally passed into the <Button>
component