HOC = function(컴포넌트) { return 새로운 컴포넌트; }
React가 아닌 React에 구성에 따른 방법
Relay - fragment-container(HOC)
https://relay-ko.github.io/docs/v8.0.0/fragment-container
render() {
const EnhancedComponent = enhance(MyComponent);
// unmount/remount가 각각 일이남 불릴떄마다
return <EnhancedComponent />;
}
// Define a static method
WrappedComponent.staticMethod = function() {/*...*/}
// Now apply a HOC
const EnhancedComponent = enhance(WrappedComponent);
// The enhanced component has no static method
typeof EnhancedComponent.staticMethod === 'undefined' // true
해결방안 : 라이브러리 컴포넌트 생성시 아래와 같은 형태로 코딩 가능import hoistNonReactStatic from 'hoist-non-react-statics';
function enhance(WrappedComponent) {
class Enhance extends React.Component {/*...*/}
hoistNonReactStatic(Enhance, WrappedComponent);
return Enhance;
}
https://github.com/mridgway/hoist-non-react-statics