0

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}) => () => {
             /* this line is never reached */
        }
    })
 )

For some reason the validate handler never executed.

Ideas?

andresmijares
  • 3,658
  • 4
  • 34
  • 40

1 Answers1

0
 const validateWithState = compose(
     withState('current', 'handleChange', {}),
     withState('isValid', 'validate', false),
     withHandlers({
        validate1: () => () => {
        }
     }),
     withHandlers({
        handleChange: ({current, handleChange, validate1}) => () => {
              /* logic here */
              handleChange(current, () => {
                   validate1() /* <--- here */
              })
        },
    })
 )

Probably we can't access in a function which is defined in same withHandlers. It's a bit redundant but we can access if we have previous withHandlers.

banyan
  • 3,837
  • 2
  • 31
  • 25