hoist-non-react-statics is a focused utility library for React applications designed to copy non-React specific static properties from a child component to a parent component. It functions similarly to `Object.assign` but intelligently blacklists React's internal static keywords to prevent unintentional overrides. This mechanism is critical for Higher-Order Components (HOCs) to correctly preserve static methods, `propTypes`, `defaultProps`, or other custom static properties from the wrapped component, preventing their loss during composition. The current stable version is 3.3.2. The package maintains a stable release cadence primarily driven by React's evolution (e.g., ForwardRefs support) and TypeScript definition enhancements, ensuring broad compatibility across various React versions. Its key differentiator is its precise targeting of user-defined static properties while respecting React's internals, solving a common HOC pattern challenge documented by React itself.
npm install hoist-non-react-staticsVerified import paths — ran on the pinned version, not inferred.
Demonstrates the core usage of `hoistNonReactStatics` within a Higher-Order Component (HOC) to transfer static methods and properties from a wrapped component to the HOC itself, preventing loss of functionality or metadata.
Ensure all static properties intended for hoisting are enumerable. Review your component's static definitions for potential non-enumerable properties.
Upgrade to `hoist-non-react-statics@3.x` or later to ensure compatibility with `ForwardRef` components.
If IE8 support is required, ensure you are using a robust `Object.defineProperty` polyfill that addresses IE8's deficiencies.
Carefully review the `exclude` object (third parameter) to ensure only truly unwanted statics are listed. When in doubt, omit the third parameter.
Install and include a comprehensive polyfill for `Object.defineProperty` to fix its broken implementation in IE8.
Upgrade `hoist-non-react-statics` to version 3.x or higher to gain proper `ForwardRef` support.
Ensure you are calling `hoistNonReactStatics` correctly after defining your HOC. If on `v2.x` or later, verify the static property is enumerable. If using a third parameter to `hoistNonReactStatics`, ensure the static method is not accidentally excluded.
No dependency data recorded yet.