4 ms·
This is interesting. I'll have to spend some time mulling over this before the benefits sink in. It seems like a much more confusing and less composable API tha
by baddox 8y ago
This is interesting. I'll have to spend some time mulling over this before the benefits sink in. It seems like a much more confusing and less composable API than recompose, which is how I add state, lifecycle, and other React class features to functional components. I've been completely avoiding React classes for a while now and using stateless components with recompose for over a year now, and I find it to be a wonderful architecture for component testability and reusability.
https://github.com/acdlite/recompose/blob/master/docs/API.md https://github.com/acdlite/recompose/blob/master/docs/API.md
- sktrdie 8y agoRight but with recompose you get extra wrapping components in your tree which is what they were trying to avoid.
- paultannenbaum 8y agoWhat 'tree' are you referring to? Higher order components are just functional components that accept a component as a argument and return a new component. There aren't any additional nodes added to your VDOM unless you specifically make a HOC that does that.
- renke1 8y agoThe component tree.
- paultannenbaum 8y agoThen yeah you are incorrect. You are not adding any additional components to the tree. Higher order components are just a design pattern. How you implement that pattern will decide on the component tree, but there is no additional "wrapping" penalty for using them.
- mcphage 8y agoThe author of recompose just end of life'd it today in favor of Hooks. Read his comment on the top of the recompose readme.
- acemarke 8y agoThat author is Andrew Clark, who's also a React core team member and helped design and implement hooks in React :)
- baddox 8y agoStill, I'll be looking into the hooks pattern and determining how it will work for my projects and especially how easy it will be to port my large number of reusable HOCs from recompose to React hooks.
- renke1 8y agoRecompose is not really compatible with TypeScript (no clue about Flow). Render props are a good alternative but the nesting made composing a bit cumbersome. Hooks are easy to type and compose quite fine it seems.
- baddox 8y agoI don't know much about TypeScript, but is any React HOC function composition compatible with it? It seems like it would be difficult for TypeScript to typecheck a compose function where you can do compose(hoc1, hoc2, hoc3), where each HOC renders a child component with some props added.
- renke1 8y agoYou can write HoC with working typings [1]. As far as I know the compose function is harder to type because of the varargs it uses (although I heard recent TS versions can actually handle that). [1]: https://medium.com/@jrwebdev/react-higher-order-component-patterns-in-typescript-42278f7590fb https://medium.com/@jrwebdev/react-higher-order-component-pa...