• Design
  • Shotty
  • Blog
  • Reading
  • Photos
Menu

Jacob Ruiz

Product Designer
  • Design
  • Shotty
  • Blog
  • Reading
  • Photos
hero (1).png

Tutorial: How to use SVGs from Sketch in React

January 30, 2019
  1. Export the SVG from Sketch.

Screenshot 2019-01-30 11.58.19-annotated.png


2. Open the SVG file your text editor to see the code.

Screenshot 2019-01-30 12.02.28.png

3. Wrap it in a component and clean up some of the junk.

Screenshot 2019-01-30 12.06.57.png

Sketch adds a bunch of useless markup that you can remove. You should end up with something like the code above. Note that I’ve added classNames to the bounding box, and the heart path itself. This will let me target these shapes directly in my CSS later when I want to change the color on hover, for example.

4. Style it with CSS

Your final component should look something like this: (I’m using styled-components for styling)

Screenshot 2019-01-30 12.12.09-stiched.png

Notice how we can use those classNames we added to target individual shapes within the SVG. This lets us transition from white to red when the user hovers their mouse over the button.

5. Your SVG component is ready to use!

Here’s a demo of our LikeButton component, with animated SVG transitions in action:

like button demo.gif

That’s it! If you have questions feel free to leave them in the comments.

In Code, Design, Javascript Tags react, svg, design, development, code
← React talk: Recomposing your React application by Andrew ClarkPricing Design Work & Creativity →
shotty-skinny2x.jpg

Shotty - Faster Access To Your Screenshots on Mac

Shotty is an award-winning Mac app I created to give you instant access to all your recent screenshots, right from the menu bar. You can even add annotations on-the-fly. Stop wasting time digging through Finder for your screenshots. I promise it’ll change your workflow forever (just read the App Store reviews!).



Most popular

information-architecture

Information Architecture: The Most Important Part of Design You're Probably Overlooking

Follow @JacobRuizDesign