Unfortunately this approach just keeps creating new instances of a p5 component on each "hot update" when using create-react-app or similar.
A solution can be found here lloydatkinson.net/posts/2022/how-t...
Basically, if you follow the example in the comments above all you need to do is:
useEffect(() => { const myP5 = new p5(Sketch, myRef.current); return myP5.remove; },[])
This will remove the current p5 instance and creates a new one on the next render
yess.. did you find a solution for this? I'm trying to create a sorting visualizer using react and p5 and it's just not working..
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Unfortunately this approach just keeps creating new instances of a p5 component on each "hot update" when using create-react-app or similar.
A solution can be found here lloydatkinson.net/posts/2022/how-t...
Basically, if you follow the example in the comments above all you need to do is:
This will remove the current p5 instance and creates a new one on the next render
yess.. did you find a solution for this? I'm trying to create a sorting visualizer using react and p5 and it's just not working..