Recompose: withState and withHandlers must go in a specific order

Created on 23 May 2017  路  4Comments  路  Source: acdlite/recompose

I don't really know why this is true but I found if you do

compose(withHandlers(...), withState(...))

instead of

compose(withState(...), withHandlers(...))

The state props inside of the handlers will be undefined. This was confusing me for quite a while.

This is especially confusing because I expect the composed functions to run right-to-left and I wouldn't expect that the handlers would need to get added prior to the state mixin for the props to be available.

Most helpful comment

https://medium.com/@icelabaratory/why-recompose-uses-compose-19e6cb1430ac

All 4 comments

https://medium.com/@icelabaratory/why-recompose-uses-compose-19e6cb1430ac

@jethrolarson Think of them like from top to bottom

compose(
  withState(...),
  withHandlers(...)
)

okay, so is this the same reason that lenses compose left-to-right?

Just ordinary compose definition, having that we compose enhancers. Have no idea what lenses means. I'll close this as nothing to discuss here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xialvjun picture xialvjun  路  4Comments

cdomigan picture cdomigan  路  4Comments

finom picture finom  路  3Comments

rockchalkwushock picture rockchalkwushock  路  3Comments

gajus picture gajus  路  4Comments