Since content
does not support HTML, you need to get the HTML content of the svg icon using ReactDOMServer.renderToStaticMarkup
and then convert it to a data URL like this:
import ReactDOMServer :
import ReactDOMServer from "react-dom/server";
need a state variable for data URL:
const [muiIconContent, setMuiIconContent] = React.useState();
convert svg component to data URL:
useEffect(() => {
const iconSvg = ReactDOMServer.renderToStaticMarkup(<ArrowLeftIcon />);
const svgIconWithXlmns = iconSvg.replace(
"<svg ",
'<svg xmlns="http://www.w3.org/2000/svg" '
);
const resultUrl = "url('data:image/svg+xml," + svgIconWithXlmns + "')";
setMuiIconContent(resultUrl);
}, []);
add data URL to style:
sx={{
"&.Mui-selected::before": {
content: muiIconContent,
width: 30
}
}}
You can take a look at this sandbox for a live working example of this approach.