Skip to content
Advertisement

Polygon mask SVG image not working for tsparticles in React

I have a React project which I would like to embed my logo as a polygon mask using tsparticles. It works normally if I use the sample code from the official documentation page, however if I try to use the polygon mask option, it seems that it could not detect the SVG format. I don’t know whether this is a browser issue or not.

Below is the original code from codepen by the creator embedded to my React project. I have my own logo which I store locally but for this question, I’m going to use the code from the original author of the code.

JavaScript

Advertisement

Answer

The Polygon Mask feature requires pathseg library to work correctly in some browsers (Chrome removed the SVG 1.1 support in a recent version)

pathseg is a client-side library like tsParticles, so if you are using a framework that uses SSR you need to check the documentation for the client-side imports.

I have a working sample with Next.js here

This is the code needed for Next.js before returning the <Particles /> component:

JavaScript

If you are using React client-side just import pathseg like this:

JavaScript

This should fix your issue.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement