-
Notifications
You must be signed in to change notification settings - Fork 46
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
Is it possible to use this in a hook? #44
Comments
To give an example of what I am trying to do:
|
@subtext916 hi can you please share code when is failing on |
Exact details... React project with the following files: index.tsx:
App.tsx:
useCanvas.tsx:
Now, run react project... Modify App.tsx or index.tsx, it crashes with the clearRect error. Am I doing something wrong? |
Also, could it be related to this topic? fabricjs/fabric.js#8299 |
Oh, one other detail. I am using: |
not sure, can you prepare a codesanbox runtime, I think based on the sample code, there is no benefit for now to separate hook from canvas component, all together can be inside Canvas component (don't think returning component from hook looks like a good pattern) |
Hello, I have been exploring this solution and wanted to wrap it in my own hook to eliminate the "fabricjs" specific stuff and create a more generic "useCanvas" hook which returns a Canvas (instance of the FabricJSCanvas) and some methods to work with it, which all use the "editor" returned from the fabricjs-react hook.
I am finding that this approach does not work because if I make a change to my App.tsx parent component, which triggers a re-render (hot deploy), the whole thing crashes with the error:
TypeError: Cannot read properties of null (reading 'clearRect')
I have tried adding a useEffect return function to call editor.canvas.dispose() editor.canvas.off() editor.canvas.clear() and I cannot find a way around this problem. Is this a problem? Am I using this hook wrong? Any advice would be appreciated.
The text was updated successfully, but these errors were encountered: