[SalesForce] How to create a reusable lightning web component icon using a custom SVG file

I want to create a reusable icon as a lightning web component. I found the following documentation:

https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.use_svg_in_component

I created a blank lwc and a added the SVG file with the same name as the component into the directory.

How can I use this as an icon?
My file strucure is:

 _
|
|customWarningIcon.html
|customWarningIcon.js
|customWarningIcon.js-meta.xml
|customWarningIcon.svg
|_

How can I use this icon now in other lightning web components?

`<lightning-icon iconName=?????></lightning-icon`>

Best Answer

You can't. The svg resource of a component is used to show a custom icon in Community Builder and App Builder. Further, lightning-icon only provides access to standard SLDS icons, not custom icons. You can Instead put the svg directly in to a component's template, or use a static resource to load the svg, as outlined in that same document that you've linked.

Related Topic