What is hoist-non-react-statics?
The hoist-non-react-statics package is used to copy non-react specific statics from a child component to a parent component. This is often used in higher-order component (HOC) patterns, where the HOC wraps a child component but needs to expose the same static methods as the child.
Hoisting non-react statics
This feature allows you to automatically copy static methods from a child component to a parent component, which is useful when creating higher-order components that should not interfere with the static methods of the wrapped component.
import hoistNonReactStatics from 'hoist-non-react-statics';
function enhance(WrappedComponent) {
class Enhance extends React.Component {
/* ... */
}
hoistNonReactStatics(Enhance, WrappedComponent);
return Enhance;
}
// Usage
// If WrappedComponent had static method foo(), Enhance will also have it.