Show HN: Make SVGs interactive in React with 1 line

shantingHou | 54 points

I love playful interaction too, but you can get all this for free: SVGs are natively interactive.

Here's your demo in 45 lines of SVG and CSS: https://codepen.io/paulirish/pen/gbOZXJp

paulirish | 3 months ago

Awesome work! Not sure if this is intentional but it looks like the (lack of) contrast on the text vs background color is making it hard to read anything on the landing page.

yomielu | 3 months ago

This example doesn't seem to work, I hover it and nothing happens, in incognito, chrome latest: https://svggles.vercel.app/?tab=Documentation%2FHover%2FAnim...

simlevesque | 3 months ago

Depending on what you're doing, I find SVG manipulation in React to come out pretty well. I've used it for overlays on scanned documents and basic charts without much issue at all.

tracker1 | 3 months ago

Did you consider using lottie and its interactivity? What were the tradeoffs?

khaki54 | 3 months ago

Your landing page made my 9 year old laugh. Good work!

hersko | 3 months ago
[deleted]
| 3 months ago

Looks cool but isn't this just using gsap and having a wrapper around it?

abdulyki | 3 months ago

Doesn't seem to do anything in firefox either.

ckemere | 3 months ago

looks cool, you should probably gitignore some of the dirs there though

1ilit | 3 months ago

It seems unusual to make the package name so different from the project name.

Also, the instructions for converting svg to react component work sometimes. It won't work if your svg has any style attributes for example. React also warns on some valid svg attributes, such as this one.

    <rect x="11" y="11" width="8" height="8" stroke="green" clip-path="circle() view-box" />
I've spent at least a day cleaning up after devs who just dropped inline SVG content into react components without checking whether it works. If you actually had a reliable way of embedding SVG in JSX in such a way that it worked with react, I might have use for it on occasion.

The given code example is missing a right angle brace on the `<svg` line.

recursive | 3 months ago