I might be being a bit dumb but why do you need the event? If you're just interested in passing the changed value you can use useEffect, or am I missing something?
I writeβ code and prose.
https://github.com/rpldy/react-uploady - Modern file uploading components & hooks for React. https://whitecloudsbook.com - My first sci-fi novel.
Thats indeed a possibility. If you never need the event object then its OK to just expose the value. However, React's onChange does give you the event. And when writing low level components and trying to be as transparent as possible, we attempt to provide as many options to the consuming code.
It means that the "native" onChange event from React (ex: user types a value directly) will be able to pass the event object. While custom interactions (like the up/down buttons) wont and there will be inconsistency between these types.
This article shows a solution that aims to provide the most transparent and consistent experience for anyone consuming this type of component.
You basically use this hook the same way you use React.useState but you have to pass in a ref target when you initialise it also it returns 3 items rather than 2, [state, setState, callStateChange].
That last function will change the value of the input and trigger an event for your onChange to pick up and deal with.
Here's a working example.
Unless I've totally misunderstood again π
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I might be being a bit dumb but why do you need the event? If you're just interested in passing the changed value you can use useEffect, or am I missing something?
Thats indeed a possibility. If you never need the event object then its OK to just expose the value. However, React's onChange does give you the event. And when writing low level components and trying to be as transparent as possible, we attempt to provide as many options to the consuming code.
It means that the "native" onChange event from React (ex: user types a value directly) will be able to pass the event object. While custom interactions (like the up/down buttons) wont and there will be inconsistency between these types.
This article shows a solution that aims to provide the most transparent and consistent experience for anyone consuming this type of component.
OK, I think I understand the problem now π
I think this custom hook will fix your issues.
You basically use this hook the same way you use
React.useState
but you have to pass in a ref target when you initialise it also it returns 3 items rather than 2,[state, setState, callStateChange]
.That last function will change the value of the input and trigger an event for your
onChange
to pick up and deal with.Here's a working example.
Unless I've totally misunderstood again π