-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
onInject, onDispose #52
Comments
Hmm. I see your point but I think it's still potentially useful to expose these callbacks, because they're a lot easier to use - particularly onDispose, since otherwise you would have to keep track of the workspace instance yourself. Here's a comparison: function MyComponent() {
useBlocklyWorkspace({
...,
onInject: (workspace) => { installPlugin(workspace); },
onDispose: (workspace) => { removePlugin(workspace); },
});
} vs. function MyComponent() {
const { workspace } = useBlocklyWorkspace({ ... });
const [prevWorkspace, setPrevWorkspace] = useState();
React.useEffect(() => {
if (prevWorkspace) {
removePlugin(prevWorkspace);
}
setPrevWorkspace(workspace);
installPlugin(workspace);
}, [workspace]);
} From my point of view, the onInject/onDispose version is much cleaner to read and easier to write. I do agree it's not strictly necessary but I think it's a nice convenience for users. |
Actually the useEffect callback captures the workspace and you return the cleanup function from the useEffect callback.
|
Oh, gotcha - that's a good point. In that case, yeah, I think I'm ok with removing those callbacks and instead adding that example to the documentation. |
Tested as working on my side :) |
Have you given a tough about enabling discussions here? |
Thanks for testing! Re discussions, I haven't really thought about it very much. I'm a little wary of it since it seems like it would encourage people to ask questions, and as I said in the readme I haven't really got a lot of time for this project anymore since I no longer work at a place that uses it. If I were to enable discussions on here, I think I would want to have volunteers who have agreed to help answer questions there. I'd help as much as I can, of course, I just want to set proper expectations about it. |
In retrospect, these 2 callback can be replaced with useEffect
react-blockly/src/useBlocklyWorkspace.js
Line 25 in bdf8bde
The text was updated successfully, but these errors were encountered: