GithubHelp home page GithubHelp logo

Comments (8)

kuchta avatar kuchta commented on April 27, 2024 2

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

kuchta avatar kuchta commented on April 27, 2024 1

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

bayareaunicorn avatar bayareaunicorn commented on April 27, 2024 1

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.

Gregoor avatar Gregoor commented on April 27, 2024 1

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.

Gregoor avatar Gregoor commented on April 27, 2024 1

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.

eqpoqpe avatar eqpoqpe commented on April 27, 2024

um, cool

from react.

bayareaunicorn avatar bayareaunicorn commented on April 27, 2024

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

from react.

kuchta avatar kuchta commented on April 27, 2024

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

from react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.