簡體   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