Comments (4)
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.
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.
Solution:
function(WrappedComponent) {
class Component extends PureComponent {
....
}
const Hoisted = hoistNonReactStatics(Component, WrappedComponent);
Hoisted.defaultProps = WrappedComponent.defaultProps;
return Hoisted;
}
from hoist-non-react-statics.
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)
- Minified build in npm package makes auditing difficult
- how can I use this package to extract atrributes of dynamic import react component
- Allow react version ^17 HOT 3
- `isMemo` check always returns false for components HOT 2
- Please update description in understendable way
- tsc build declaration error: Subsequent property declarations must have the same type.
- error: Error: While trying to resolve module `hoist-non-react-statics`
- Please release a new version which uses inclusive language
- React.forwardRef results in propTypes etc. being hoisted HOT 8
- Drop React <16.0.0 support? HOT 5
- missing dist/ folder in 3.3.0 release on GitHub HOT 3
- Use the latest react-is feature "isMemo" but without upgrading to the correct version of react-is HOT 11
- When hoisting: Keep prop value if context value is undefined HOT 7
- Object.getPrototypeOf called on non-object HOT 1
- Reduce bundle size HOT 4
- Incorrect AMD definition HOT 2
- Remove publishConfig block from package.json HOT 3
- Please tell Version for react-redux HOT 1
- Improve typing of third argument 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 hoist-non-react-statics.