question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add React SVGR Support

See original GitHub issue

Which version are you using? Ex. 1.19.2 1.28.1

Is the latest version affected? Yes

You can checkout latest version here

  • Yes
  • No

Which library are you using?

  • Vanilla JS (tsparticles)
  • React (react-tsparticles)
  • Vue.js 2.x (particles.vue)
  • Vue.js 3.x (particles.vue3)
  • Angular (ng-particles)
  • Svelte (svelte-particles)
  • Preact (preact-particles)
  • Inferno (inferno-particles)
  • jQuery (jquery-particles)
tsParticles Configuration
const config: RecursivePartial<IOptions> = {
  fpsLimit: 60,
  interactivity: {
  	detectsOn: "canvas",
  	events: {
  		onClick: {
  			enable: true,
  			mode: "push",
  		},
  		onHover: {
  			enable: true,
  			mode: "repulse",
  		},
  		resize: true,
  	},
  	modes: {
  		bubble: {
  			distance: 400,
  			duration: 2,
  			opacity: 0.8,
  			size: 40,
  		},
  		push: {
  			quantity: 2,
  		},
  		repulse: {
  			distance: 200,
  			duration: 0.4,
  		},
  	},
  },
  particles: {
  	collisions: {
  		enable: false,
  	},
  	move: {
  		direction: "none",
  		enable: true,
  		outMode: "bounce",
  		random: true,
  		speed: 8,
  		straight: true,
  	},
  	number: {
  		density: {
  			enable: true,
  			value_area: 800,
  		},
  		value: 10,
  	},
  	opacity: {
  		value: 0.8,
  	},
  	shape: {
  		type: ["image"],
  		image: {
  			src: <MyCustomIcon className="text-primary" />,
  		},
  	},
  	size: {
  		random: true,
  		value: 50,
  	},
  },
  detectRetina: true,
}

Is your feature request related to a problem? Please describe.

The feature that I am requesting is nothing really serious but a great addition to the react-tsparticles library. If react-tsparticles could support SVGR(SVG React) then we can make the particles react to light mode /dark mode toggles.

For example, I have a custom Icon that will change color depending on whether light mode is turned on or dark mode is turned on.

Describe the solution you’d like The solution that I think is doable and easier to develop is to add the type component to shape.type and then add a new property to the shape called component which will take in a React.FC as a value.

Describe alternatives you’ve considered None as of now

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
utkarshk384commented, Jun 16, 2021

Oh worked, Thank you

1reaction
utkarshk384commented, Jun 16, 2021

@matteobruni Thank you for the quick fix. Now I am able to theme the particles depending on the theme system.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Options - SVGR
Transforms SVG into React Components. ... "classic": adds import * as React from 'react' on the top of file ... SVG props. Add...
Read more >
How to use SVGs in React | Sanity.io guide
Include SVGs directly in JSX. JSX supports all SVG tags. We can (almost) paste the SVG directly into our React components! This is...
Read more >
React SVG: How to use SVGs best in React - CopyCat Blog
Converting SVG into a react component is another approach to using SVG in react. This technique is supported by default by Create-react-app and ......
Read more >
How to Import SVGs in a React and Vite app - freeCodeCamp
How to Import SVGs by Adding them Directly as JSX. JSX supports the svg tag, so we can copy-paste the SVG directly into...
Read more >
How to use SVGs in React - LogRocket Blog
SVG is a vector graphics image format based on XML. ... SVGs help with performance and add a great level of animation, interactivity, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found