React Core & Hooks (407 Qs)•Part 9: React Hooks Deep Dive (262 - 316)
How do you create HOC using render props?
junior LevelCode ExampleComponentsHooks
You can implement most higher-order components (HOC) using a regular component with a render prop. For example, if you would prefer to have a withMouse HOC instead of a <Mouse> component, you could easily create one using a regular <Mouse> with a render prop.
javascript
function withMouse(Component) {
return class extends React.Component {
render() {
return (
<Mouse
render={(mouse) => <Component {...this.props} mouse={mouse} />}
/>
);
}
};
}
arduino
This way render props gives the flexibility of using either pattern.