繁体   English   中英

重组:等价于withState / withHandlers与withStateHandlers的组合

[英]Recompose : Equivalant of the combination withState/withHandlers with withStateHandlers

一个简单的问题:如果我想使用withStateHandlers而不是withState / withHandlers夫妇。 这等效于什么:

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

感谢您的回答 :)

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM