Skip to content
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

Open
kuchta opened this issue Dec 5, 2023 · 9 comments
Open

Feature: useEffectEvent should be useCallback without dependency array #27793

kuchta opened this issue Dec 5, 2023 · 9 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@kuchta
Copy link

kuchta commented Dec 5, 2023

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...🙏🏻✌🏻👀

@kuchta kuchta added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Dec 5, 2023
@eqpoqpe
Copy link

eqpoqpe commented Dec 6, 2023

um, cool

@bayareaunicorn
Copy link

Seems useless why not just pass an empty array in your useEffect to render only once?

@kuchta
Copy link
Author

kuchta commented Dec 9, 2023

@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...

@bayareaunicorn
Copy link

I see perhaps useChildCallback or useCallbackChild would be a better fit?

useCallback Use Case: It is used to prevent unnecessary re-renders of child components by memoizing a function instance and changing the callback only when one of its dependencies changes .
useEffectEvent Use Case: It provides a more powerful alternative to useCallback with no dependencies, allowing for constant reference to a function and preventing unnecessary re-renders of child components

@kuchta
Copy link
Author

kuchta commented Dec 13, 2023

@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.

@Gregoor
Copy link

Gregoor commented Mar 17, 2024

I think that would be unwise, the rules of useEffectEvent are that it's only to be called from effects and not passed to child components. useCallback does not have that limitation. Having semantics diverge this massively by just (not) passing a dependency array in, would lead to confusion.

@kuchta
Copy link
Author

kuchta commented Mar 17, 2024

@Gregoor Fair point. So maybe useEffectCallback would be better choice, since calling it Event is quite misleading as well...

@Gregoor
Copy link

Gregoor commented Mar 17, 2024

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.

@rickhanlonii
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

5 participants