Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> HOC's have a bunch of downsides, imo the most obvious one is the props; you need to pass the previous props, and merge in the new ones.

Render props (aka. "function as children") are much more free form than HOCs - they allow you to "compose the props" at the site of usage, as opposed to the component implementation.

I don't think there is a use case that HOC covers that cannot be done with render props - please correct me if I'm wrong.



You are not wrong, I think renderprops are valid, and I still use them in some situations.

They are imo not ideal as they are hard to memoize because of the render function. It’s funny that if you try to memoize renderprop components you likely have to use some sort of inputs array just like hooks.

Besides the memoization issue it also gets pretty messy if you need to implement many of them. Instead of just putting things in variables you are now nesting many levels deep.

I think renderprops and hooks are functionally not that different, but hooks have better ergonomics when using many.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: