Comments (8)
@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.
from react.
@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...
from react.
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
from react.
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.
from react.
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.
from react.
um, cool
from react.
Seems useless why not just pass an empty array in your useEffect to render only once?
from react.
@Gregoor Fair point. So maybe useEffectCallback would be better choice, since calling it Event is quite misleading as well...
from react.
Related Issues (20)
- Bug:
- Bug: ESLint rule doesn't catch mistake with non-exhaustive dependencies
- Fix gap between footer logo and links HOT 16
- Source is not showing HOT 7
- Bug: Hydration error due to <button> HOT 6
- Bug: Search functionality not working correctly on react.dev in Safari on iOS real device (iPhone 12 Pro) HOT 2
- Bug:
- Google Translate causing "Text content does not match server-rendered HTML" HOT 1
- Bug: useFormState formAction becomes null in strict mode HOT 1
- Bug: Source is not showing in 5.0.2 HOT 8
- Question and suggest: The official identifier of Server Compnoent and Client Component HOT 3
- Bug: when installing the application, the old version of "react-scripts" is installed HOT 1
- Bug: Uncaught DOMException: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string. HOT 4
- Bug: optimistic state (useOptimistic) shows both optimistic and returned from server data when running several async actions HOT 6
- [DevTools Bug]: React Profiler reports higher hook numbers than shown in Components HOT 2
- about the react performance (how to improve it) HOT 3
- Bug: use() hook HOT 4
- Bug: Flight (RSC) examples are not accessible HOT 1
- useMemo reruns when the dependencies not changed when memoised value is a fn HOT 3
- Bug: [Flight] Async server components in `ai/rsc` not rendered correctly HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react.