-
Notifications
You must be signed in to change notification settings - Fork 33
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
Use Callback #54
Comments
Seems like you could just use fn' <- Hooks.useMemo deps \_ -> fn would be the same as a hypothetical fn' <- Hooks.useCallback deps fn right? |
Wow idk why the issue description was cut. What i meant to say was: i see |
It seems about right, but the same applies in regular js, yet I guess it's because it is "unnecessary" or something similar in PureScript? |
Yeah, it's a combination of me naming some functions badly in previous versions plus it being redundant. Leaving it in would have caused confusing errors for those upgrading. I'm not opposed to adding it now, but also.. it's literally |
I was wondering more if the whole pattern was unnecessary or something, meaning declaring functions inside the body of a component does not cause React to re-render sub-components diffing a new function all the time, etc, but if it is the same case then having
That's fine, considering PS commonality of having a bunch of ergonomic signatures (like But it's fine, I was mostly wondering about the former, I would "vote" for having it, but if it is trouble or confusing in PS, that's fine too, no need to make a change just for that. |
That's true, I don't mind adding it. For a little more background, I think PS devs are less likely to be thinking about reference equality at all, especially for functions, and just eating that performance cost until it actually becomes a problem. On the flip side, it's become fairly expected in JS-land and the more you see it the more you keep using it. In most cases it's a premature optimization. You can reach for these tools in PS if you need them ( |
It would be great if there would be What option would you prefer @megamaddu ? Adding useCallback :: forall deps a. Eq deps => deps -> a -> Hook (UseMemo deps a) a
useCallback deps fn = useMemo deps (const fn) or actually calling Even though react docs say it's equivalent to, react team could decide to change internals of both functions or remove one of them in a breaking change in the future. And I personally tend to just exposing these functions from the react library and would go with the latter option (calling |
Hi! Thanks a lot for this amazing package ✨
I cannot find an example of
React.useCallback
I see it was deprecated on what seems to bev5.x
what is the correct way to "useCallback" in a hook?Sorry if it is a silly question I'm learning purescript
The text was updated successfully, but these errors were encountered: