react-use icon indicating copy to clipboard operation
react-use copied to clipboard

useMediatedState should allow type conversion

Open mendrik opened this issue 1 year ago • 0 comments

What is the current behavior?

current typing for useMediatedState expects the mediated state to be the same as the initial/incoming value

What is the expected behavior?

it should allow to map onto another type i.e.: const [count, setCount] = useMediatedState(parseInt, 0) or explicitly: const [count, setCount] = useMediatedState<number, string>(parseInt, 0) (order could be also switched depending on the pov)

A little about versions:

  • OS: windows
  • Browser (vendor and version): chrome
  • React: v18
  • react-use: 17.4.0
  • Did this worked in the previous package version? doubt it

mendrik avatar Oct 12 '22 10:10 mendrik