I have the following code. Initially, when I select 2022 I don't see the value logged in the console, and also if I select 2021 then '2022' gets logged in the console. I also tried changing the initial state to 2022 by
I tried the below code,
const [selecteddropdown,setdropdown] = useState(2022);
but still, the selected value is not getting printed. What do I need to change?
const Filter = () => {
const [selecteddropdown,setdropdown] = useState('');
const handleChange = (event) => {
setdropdown(event.target.value);
console.log(selecteddropdown);
};
return (
<div className='expenses-filter'>
<div className='expenses-filter__control'>
<label>Filter by year</label>
<select value={selecteddropdown} onChange={handleChange}>
<option value='2022'>2022</option>
<option value='2021'>2021</option>
<option value='2020'>2020</option>
<option value='2019'>2019</option>
</select>
</div>
</div>
);
};