Skip to content

Instantly share code, notes, and snippets.

@M-ZubairAhmed
Created July 6, 2020 17:11
Show Gist options
  • Select an option

  • Save M-ZubairAhmed/4ada48d6658ffc24cde39c0568aa2d68 to your computer and use it in GitHub Desktop.

Select an option

Save M-ZubairAhmed/4ada48d6658ffc24cde39c0568aa2d68 to your computer and use it in GitHub Desktop.
A simple description on how to use svg in react

If the app uses custom webpack configuration, then loader is needed to handle svgs in your app. Lets use SVGR webpack loader.

yarn add @svgr/webpack --dev

and then in your webpack config file add the following rule :

{
  test: /\.svg$/,
  use: ['@svgr/webpack'],
}

and then directly import the svg as react components

import IconGearFill from 'bootstrap-icons/icons/gear-fill.svg'

for styling you can pass on style or classname prop, and they will be applied on to your svg component.

<IconGearFill className="text-success" style={{ fontSize: '1.8em' }} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment