Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import hoistNonReactStatic from 'hoist-non-react-statics';
const withSearch = (WrappedComponent) => {
class WithSearch extends React.Component {/*...*/}
hoistNonReactStatic(EithSearch, WrappedComponent);
return WithSearch;
}
// Define a static method
ProductsList.staticMethod = function() {/*...*/}
// Now apply a HOC
const ProductsListWithSearch = withSearch(ProductsList);
// The enhanced component has no static method
typeof ProductsListWithSearch.staticMethod === 'function' // true
// Define a static method
ProductsList.staticMethod = function() {/*...*/}
// Now apply a HOC
const ProductsListWithSearch = withSearch(ProductsList);
// The enhanced component has no static method
typeof ProductsListWithSearch.staticMethod === 'undefined' // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.