In the course of my final project at the Flatiron School in software engineering, I really wanted to push my skills farther than what I was comfort...
For further actions, you may consider blocking this person and/or reporting abuse
Thank you so much! I was initially using a package that ultimately made what I was trying to do more complicated (I also needed the ability for user input). I'd probably be tearing my hair out if I didn't stumble upon this.
Awesome! Stoked to help
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..
Hello, thanks so much for this constructive document answer. I am new to react and i am developing a project with my friends. I have a doubt regarding the same topic. is there a way to do this as a functional component?
import React, { useEffect } from 'react';
import p5 from 'p5';
const App = () => {
const myRef = React.createRef();
const Sketch = (p) => {
}
useEffect(() => {
const myP5 = new p5(Sketch, myRef.current)
},[])
}
export default App;
Thanks for the response @anshul16. It will surely help someone in the community.
Hello Christian,
Thank you.
You can test your code here P5inReact
Regards
THANK YOU SO MUCH. I don't know why we can not import Javascript functions directly in to React components. I guess I am missing something fundamental. Your work is really helpful for my current project. P5.js is great. Cheers.
edit: I also love the way you've structured the projects. Great balance between readability and modularity.
can you be a bit more clear about why this is a better option than using the wrapper libraries, that people have put a lot of work into? I assume there's some complication that is created by that layer of abstraction but fear it would only be after spending a lot of time working on this that would become clear....?
Thanks, this was really helpful! I'm using p5 to make a dynamic background for my website, and I was having trouble integrating it into a React app. It's very nice to see how the whole process is put together instead of adding yet another dependency to magically make it work.
"I learned very quickly that best option is to actually just learn the tech and not treat it like a black box", this phrase couldn't be more right!
Thank you, this post was very helpful.
Christian would it be possible for you to Git a stub project? Loved the simplicity of your explanations
Thank you so much for the tutorial! I'm wondering have you tried to deploying your website? I'm trying to deploy my website which integrated p5.js with react, but it always shows that "(undefined) ReferenceError: window is not defined". Have you encountered this kind of issue?
Not all heros don't wear capes. You're a gent for posting this!
Thanks! But its truly a bummer and a pain to have to prefix every thing in p5js with something...
Really nice. Great work! Thanks for the clear writeup.
Thanks Christian! Very helpful article :)
thank you!!!