【问题标题】:Recompose : Equivalant of the combination withState/withHandlers with withStateHandlersRecompose : withState/withHandlers 与 withStateHandlers 组合的等价物
【发布时间】:2018-02-22 07:12:36
【问题描述】:

简单的问题:如果我想使用 withStateHandlers 而不是 withState/withHandlers。这个等价物是什么:

withState('value', 'updateValue', ''),
withHandlers({
    onChange: ({updateValue}) => event => updateValue(event.target.value)
})

感谢您的回答:)

【问题讨论】:

    标签: recompose


    【解决方案1】:

    withStateHandlers 没有命名为 stateUpdater(如您的情况下为 updateValue),因此您需要直接与状态交互。

    withStateHandlers(
      // you define the initial state
      { value: '' }, 
      // this is handler - you return a new state - updated value in this case
      { onChange: () => event => ({ value: event.target.value }) } 
    )
    

    【讨论】:

    • 感谢您的回答。你知道我为什么会出现这个错误吗:warning.js:35 Warning: performUpdateIfNecessary: Unexpected batch number (current 70, pending 69)
    • 现在,我只是使用 withState/withHandlers 的组合,它的作品。
    猜你喜欢
    • 2018-01-24
    • 2018-02-14
    • 2018-12-22
    • 2017-10-13
    • 2017-12-24
    • 1970-01-01
    • 2019-02-01
    • 1970-01-01
    • 2018-02-24
    相关资源
    最近更新 更多