New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do you pass value in props over to a vanilla .js class? #33
Comments
Im not sure if I understand your Problem. You want to have the e.g.:
This is currently not Possible, since the 'setup' Function is called via the p5 constructor and at this point the |
Yes, I'm trying to figure how can I pass the prop value over into setup(). I created my UI in React so that I can manipulate the parameters (propValue) If this is currently not possible, do you know if there's any hacky way? Or on top of your mind any pseudo code steps you could school me so I can go investigate?
It's interesting that it works in draw() but not setup() ? |
You can write your own e.g.:
|
Thanks @and-who
Particle.js
|
p.myCustomRedrawAccordingToNewPropsHandler = function(props) {
if (props.diameter) {
bug1.diameter = props.diameter;
bug2.diameter = props.diameter;
}
} |
@shtrih Oh awesome! I didn't know you can call your particles in the p.myCustom... function. Sketch.tsx
Particle.js
|
The newly adjusted value is passed to the particle (the shape is getting bigger) |
Weirdly when I do the same for bug1.speed (just a single digit number) it works nicely. The React slider is able to adjust the speed for the particle. |
@and-who
Currently I've this in my Sketch.tsx
p.myCustomRedrawAccordingToNewPropsHandler = function(props) { if (props.testValue) { testValue = props.testValue } }
Let's say I've a vanilla .js class file where I use it to generate particles.
How can I pass the testValue over to the .js file?
I tried to pass it into the constructor but it doesn't work?
It gives me "undefined".
How can I return the props value in p.myCustomRedrawAccordingToNewPropsHandler and store it somewhere else where I can reuse? It works in draw() but not setup().
The text was updated successfully, but these errors were encountered: