Giter Club home page Giter Club logo

Comments (4)

mridgway avatar mridgway commented on June 16, 2024 1

I don't think this is always the desired behavior for HoCs. I'd prefer to keep this out of the library and have a user land solution like @aarondancer posted.

from hoist-non-react-statics.

salmanm avatar salmanm commented on June 16, 2024 1

While it makes sense that it might not be always desired to copy the defaultProps. But the way I see it is when we wrap a component, it makes sense for the wrapper to receive the same props as the original component would receive if it were not wrapped. This could be important for so many reasons I think. For instance when an HoC wants to act based on a prop value but it didn't just because it didn't exist.

A more realistic example would be an HoC calling react-jss callback function and there we get only user specified props but not the complete props after merging with defaultProps.

Of course I'm not suggesting we should copy defaultProps by default, but we could probably have a fourth parameter say whitelist that let's user pass whatever they need.

If this sounds good, I'd be happy to PR that.

from hoist-non-react-statics.

aarondancer avatar aarondancer commented on June 16, 2024

Solution:

function(WrappedComponent) {
  class Component extends PureComponent {
      ....
  }

  const Hoisted = hoistNonReactStatics(Component, WrappedComponent);
  
  Hoisted.defaultProps = WrappedComponent.defaultProps;

  return Hoisted;
}

from hoist-non-react-statics.

s-kobets avatar s-kobets commented on June 16, 2024

I am that and doing, but I think that can doing hoistNonReactStatics, if I can that create merge request.

from hoist-non-react-statics.

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.