Recompose: withHandlers callback not working

Created on 15 May 2017  ·  7Comments  ·  Source: acdlite/recompose

Hi there,

I'm trying to exec a validation like this:

const validateWithState = compose(
    withState('current', 'handleChange', {}),
    withState('isValid', 'validate', false),
    withHandlers({
       handleChange: ({current, handleChange, validate}) => () => {
             /* logic here */
             handleChange(current, () => {
                  validate() /* <--- here */
             })
       },
       validate: ({current, isValid}) => () => {
             /* this line is never reached */
       }
    })
)

For some reason the validate handler never executed.

Ideas?

Most helpful comment

Yep :)

All 7 comments

@andresmijares All handlers can access only previously passed props. The can't access to each other. You can use two withHandlers hocs

Do you mean this possible?

withHandlers({
       validate: ({current, isValid}) => () => {
             /* this line is never reached */
       }
}),
withHandlers({
       handleChange: ({current, handleChange, validate}) => () => {
             /* logic here */
             handleChange(current, () => {
                  validate() /* <--- Now this has access to ^ */
             })
       },
}),

Thanks for ur response!

Yep :)

thank you for you fast response man!

It will be a good first PR https://github.com/acdlite/recompose/pull/333
as work on that PR seems like stopped

IMO it will be fine to have ability to have access to current handlers as at first comment.

I agree, I've been using this library since 3 days, ago, it took me 2 to understand how this works. I will try my best to collaborate.

PR to allow call internal handlers
https://github.com/acdlite/recompose/pull/401

Was this page helpful?
0 / 5 - 0 ratings