Eric Elliott
Mar 25 · 1 min read

‘If you don’t need to add logic to a component why would you wrap it in a HOC in the first place? Just pass it as a child to another component and render it with “props.children”.’

The whole point of an HOC is to add something to a component. However, if you need to customize the props or logic you’re adding to make it work properly with a specific component you’re trying to enhance, hooks may be a better fit because hooks allow you to specify how or even if props are passed to or used by the component you’re enhancing. HOCs would require you to write a container component to cutomize props and behavior for the enhanced child compoment.

Render props?

As discussed in the article, render props must always control if or how props are communicated to the enhanced components. That’s the whole point of them.

Render props also invert control, making them a little confusing and syntax-heavy. Now that we have hooks, render props are entirely redundant with hooks. I recommend using hooks instead wherever render props may have been useful before.

But because neither can compose automatically using standard function composition, neither can replace HOCs.

I wrote an entire book emphasizing how fundamental function composition is to software development. Learning the power of automatic, declarative composition will have a dramatic complexity-reducing impact on the code you write.

“Composing Software” introduction

Eric Elliott

Written by

Make some magic. #JavaScript

More From Medium

More from Eric Elliott

More from Eric Elliott

Encapsulation in JavaScript

More from Eric Elliott

More from Eric Elliott

TDD Changed My Life

More from Eric Elliott

More from Eric Elliott

Testing Software: What is TDD?

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade