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

React components aren't a 1:1 mapping to the DOM, so you could in theory have 50 HoCs wrapping a single component and it still only output one div or whatever.

Also, HoCs have somewhat fallen out of favour over time, with hooks and the child as a function/render prop style becoming more popular. I think the only HoC I consistently use these days is `connect` from `react-redux`.



You can use hooks with redux now, so what’s the purpose of using connect instead of useDispatch or useSelector?


Two big reasons: Values passed via connect can be validated by proptypes, and by using connect you can mount your component without redux. That may make sense for building shared components that may be used with redux in one part of your app, but without redux in another part. There are a lot of smaller reasons to prefer connect, but those are the big ones to me. FWIW I use both approaches depending on needs.




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

Search: