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
Feature: useEffectEvent should be useCallback without dependency array #27793
Comments
um, cool |
Seems useless why not just pass an empty array in your useEffect to render only once? |
@bayareaunicorn That's what it's typically combined with, but if you want to access actual values from a callback provided there, that's when you would want to use it. Despite it's name, experimental useEffectEvent is not an equivalent to useEffect, but to a useCallback, in a sense. That's what this issue is about, that people will probably be confused by it's name... |
I see perhaps
|
@bayareaunicorn Well, useChildCallback is probably better then useEffectEvent, but considering that people are alredy used to that returned reference from useHooks changes as often as some of it's dependencies, I think that just useCallback without any dependencies would communicate that intention better with respect to already memorized rules. |
I think that would be unwise, the rules of |
@Gregoor Fair point. So maybe useEffectCallback would be better choice, since calling it Event is quite misleading as well... |
Yeah that maps closer to my conceptualization of it as well. I think the React team's lingo might diverge here from ours though. I would be curious to read a team member's take on this. |
We're going to be iterating on this API a bit more after 19 so I wouldn't spend too much time bike-shedding the name just yet. The current distinction makes sense because the function returned from useCallback can be passed down, but useEffectEvent can only be used locally, and it would be confusing to have the same API have different prop passing semantics. We have some ideas for how to remove that restriction so we're going to investigate those options. I'll share more when we know more. |
The experimental useEffectEvent is generally something useCallback should have been without depedency array or with empty dependency array to match the behavior of useEffect. Introducing new name will just bring more confusion since it's very hard to image, what useEffectEvent should do...🙏🏻✌🏻👀
The text was updated successfully, but these errors were encountered: