Coder Social home page Coder Social logo

Comments (8)

satya164 avatar satya164 commented on May 2, 2024 1

https://github.com/bvaughn/rfcs/blob/ref-forwarding/text/0000-ref-forwarding.md

from rfcs.

satya164 avatar satya164 commented on May 2, 2024

I think onRef is a nicer API, but maybe getWrappedInstance is a better solution since the community seems to have adopted it already.

Does the HOC need withRef: true config for that

I think it's unnecessary. We just need to check if the component is a function component and not add the ref in that case.

from rfcs.

slorber avatar slorber commented on May 2, 2024

You mean checking for:

const isClassComponent = (Component: Function) => !!Component.prototype.render; ?

And if it's a class, automatically ask for ref?
Does it have any performance cost or any side effect to ask a ref even when client does not need it?

ping @gaearon @markerikson @timdorr @ericf as this solution might be backported in existing HOC libs

from rfcs.

timdorr avatar timdorr commented on May 2, 2024

We shouldn't create it if we don't need it. It's a wasted effort, especially if you have a large number of connected/HOC'ed components.

from rfcs.

satya164 avatar satya164 commented on May 2, 2024

@timdorr can you elaborate? does it have any performance implications? would be great if you could post a link where I can read more.

from rfcs.

timdorr avatar timdorr commented on May 2, 2024

There's a new API coming for refs that would make the instantiation of the ref explicit, and therefore it's upfront cost as well: https://github.com/reactjs/rfcs/blob/master/text/0017-new-create-ref.md

from rfcs.

satya164 avatar satya164 commented on May 2, 2024

@timdorr it's just a convenience API for the callback ref, right? we are not planning to use that API right now. but what is the cost? memory usage or attaching a ref deopts something?

from rfcs.

timdorr avatar timdorr commented on May 2, 2024

I don't know specifically. There's no code to go on. But one would assume createRef has some sort of cost associated with it. So, creating that ref and never using it would be a wasted effort. I'm not trying to make it into a big deal, just pointing out the inefficiency (no matter how trivial).

from rfcs.

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.