0

我正在尝试执行这样的验证:

 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 */
        }
    })
 )

由于某种原因,validate处理程序从未执行。

想法?

4

1 回答 1

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

可能我们无法访问在 same 中定义的函数withHandlers。这有点多余,但如果我们有以前withHandlers的 .

于 2017-05-15T08:39:50.890 回答