wufe / react-particles-js

Particles.js for React
https://rpj.bembi.dev/
MIT License
1.16k stars 106 forks source link

dynamically updating params #29

Closed gc closed 6 years ago

gc commented 6 years ago

I want to tie the p.js params to an object in the state of a parent component (which renders the particles component), by passing it as a prop, so that I can update the state (e.g. change the size of the particles) and have that be immediately reflected. It doesn't seem to work though.

<Particles
  width="100%"
  height="100%"
  params={this.state.ParticlesConfig}
  style={{ width: "100%", position: "absolute", zIndex: -1, backgroundColor: "#000" }}
 />

I've verified that the params are actually being updated by using the React Chrome devtools and inspecting the props of the Particles component.

wufe commented 6 years ago

The problem is going to be fixed in v2.1.2. Now the library will reset when props passed to the component change.

Notice that when props change, the canvas will reload entirely, so the particles will be deleted and replaced with new particles.