Skip to content

Instantly share code, notes, and snippets.

@mohandere
Last active May 12, 2019 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohandere/e8491f8193b104c153833083fbcce0a3 to your computer and use it in GitHub Desktop.
Save mohandere/e8491f8193b104c153833083fbcce0a3 to your computer and use it in GitHub Desktop.
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