Issue
I’m trying to use onChange
function on a slider, but I keep getting and error with the Value. Am I doing something wrong ?
I’m using TypeScript and ViteJS.
My code:
<Slider
color="success"
aria-label="Small steps"
defaultValue={0.00000005}
step={1}
marks
min={5}
max={20}
valueLabelDisplay="auto"
value={passwordLength}
onChange={(e) => setPasswordLength(e.target.value)}
/>
Solution
Looking at the error reported:
Property ‘value’ does not exist on type ‘EventTarget’
Since you are using a custom component <Slider>
, you need to explicitly tell TypeScript the type of the HTMLElement
which is your target.
Answered By – Sandro Maglione
Answer Checked By – David Marino (BugsFixing Volunteer)