1

Simple question: if i want to use withStateHandlers instead of the couple withState/withHandlers. What is the equivalant of this :

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

Thanks for your answer :)

wyeo
  • 33
  • 5

1 Answers1

2

withStateHandlers doesn't have named stateUpdater (like updateValue in your case), so you need to interact with the state directly.

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 }) } 
)
Patrik Prevuznak
  • 2,181
  • 15
  • 14
  • Thanks for your answer. Do you know why i have this error : `warning.js:35 Warning: performUpdateIfNecessary: Unexpected batch number (current 70, pending 69)` ? – wyeo Sep 15 '17 at 12:20
  • For now, i just use the combination of withState/withHandlers and it's works. – wyeo Sep 29 '17 at 19:32