How to use SVG icon sets with SSR? #56
-
Hey, const feather = require('feather-icons')
...
{feather.icons.home.toSvg()}
... It worked and the icon was rendered. After I tried to use it on my sidebar component, with and without hydration. The result was HTML code: <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-home"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path><polyline points="9 22 9 12 15 12 15 22"></polyline></svg> At least I tried the new <dangerouslySetInnerHTML>{feather.icons.home.toSvg()}</dangerouslySetInnerHTML> Am I doing something wrong? Or does it not support SVG? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Try <p dangerouslySetInnerHTML={{ __html: feather.icons.home.toSvg() }}></p> |
Beta Was this translation helpful? Give feedback.
-
Thanks but the behaviour is the same, it outputs: <dangerouslysetinnerhtml><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-home"><path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"></path><polyline points="9 22 9 12 15 12 15 22"></polyline></svg></dangerouslysetinnerhtml> |
Beta Was this translation helpful? Give feedback.
-
Yeah that's what I said in the first post, server side it worked, even without the dangerouslySetInnerHTML. But the sidebar is a client side component and inserted in MainLayout.tsx. Is there a way to get it working there? Or do you mean I should render the Sidebar server side with renderSSR? <div id="root">
<Navbar path={path} />
<Sidebar path={path} />
<div id="content">
<main class="site-content">
<div class="container pt-5">
<div class="row m-0">
<div class="col-md-12 p-3">{props.children}</div>
</div>
</div>
</main>
<Footer />
</div>
</div> |
Beta Was this translation helpful? Give feedback.
-
Sorry man I don't get it. Now it is working even inside the sidebar without hydrating it. I must have made something wrong before. Thanks! |
Beta Was this translation helpful? Give feedback.
Try