-
Notifications
You must be signed in to change notification settings - Fork 49
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
It creates new canvas once state is changed #415
Comments
This was my problem too. I ended up not using states cause it also clears the mouse event handlers on my matterjs side as the canvas gets re-rendered. I tried to use React.memo on the wrapper but I got more bad side effects. I suggest using just refs to store values and put your sketch function inside the component where the wrapper is so that it has access to the refs:
|
I think this is more to do with the fact you are trying to use I also don't believe that moving the variables into a ref is the answer either, in this case you actually have constant data and from what I can see, the OP never calls the setter function (which is also bad practice in React to pass around). In such as case I would just have a type Props = { ... }
const measurements = {...};
const sketch: Sketch<T> = p5 => {...}
export function App(props: Props) { ... } In the Just some tips. |
I'm having a problem with my code where I am using P5-wrapper/react to show the 2D model I created. However, whenever React states changes it re-creates the canvas again and again it gives warning that
WARNING: Too many active WebGL contexts. Oldest context will be lost.
.My code is a bit complex, thus I have created a simple example in this codesandbox, but I will also give a bit information.
I got
Measurement
class where I am using to set up specific measurement objects.and some variables and function:
and I have this
sketch
function I am using:problem seems to be once I click and drag any point where state changes because of
onChangeDraw
where I set the measurements into new measurements I get fromp5
side.So, also including measurements for reference:
and wrapper:
The text was updated successfully, but these errors were encountered: