hoist-non-react-statics
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
react-is | 16.13.1 | 5.33 kB | MIT | prod |
Hoist-non-react-statics is a JavaScript library that allows copying of non-react specific statics from a child component to a parent component. This is analogous to Object.assign
, but with a special feature: React static keywords are blacklisted from being overridden. This library plays a key role in aiding highest order components (HOCs) in JavaScript programming, particularly when working with React.
To use hoist-non-react-statics, first install the library into your project using npm with the following command in your terminal: npm install --save hoist-non-react-statics
. Once installed, you can go ahead and import the library into your .js file like this:
import hoistNonReactStatics from 'hoist-non-react-statics';
Then use the hoistNonReactStatics()
function by passing it two arguments: the target component and the source component, in that order. Here's an example,
hoistNonReactStatics(targetComponent, sourceComponent);
If there are specific statics you want to exclude from being hoisted, you can specify them in a third parameter like so:
hoistNonReactStatics(targetComponent, sourceComponent, { myStatic: true, myOtherStatic: true });
The main source of documentation for hoist-non-react-statics can be found at the project's GitHub repository (https://github.com/mridgway/hoist-non-react-statics). For an in-depth understanding of what this library does, consider reviewing the explanation provided in the React documentation regarding higher-order components.