Skip to content

Instantly share code, notes, and snippets.

@jayrbolton
Created February 24, 2021 05:11
Show Gist options
  • Save jayrbolton/e850cb3000a210b76603a55645d540a0 to your computer and use it in GitHub Desktop.
Save jayrbolton/e850cb3000a210b76603a55645d540a0 to your computer and use it in GitHub Desktop.
Using feathericons with Snabbdom

How to use feathericons with Snabbdom

Create an icon component function, like so:

// Pass in the icon name
module.exports = function icon (name) {
  const style = {
    width: '24px',
    height: '24px',
    stroke: 'currentColor',
    strokeWidth: 2,
    strokeLinecap: 'round',
    strokeLinejoin: 'round',
    fill: 'none'
  }
  return h('svg', {
    style,
    hook: {
      insert: (vnode) => {
        vnode.elm.innerHTML = feather.icons[name].toString()
      }
    }
  })
}

Use the insert hook to render the contents of the SVG.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment