What i have in my project is a date picker with a reset button next to it, after user select date from date picker, the date picker will show the selected date. See this image if you have dont get it yet
And what i want is to reset the date value back to this by clicking reset button.
And here is my code
I did setting value back to null using useState hook onClick the button, using useRef hook, but nothing works. Any help?
Which datepicker package do you use? This example works with react-datepicker:
import DatePicker from "react-datepicker";
const [dateValue, setDateValue] = useState(null);
<DatePicker
selected={dateValue}
onChange={d => setDateValue(d)}
/>
<button onClick={() => setDateValue(null)}>Reset</button>
Avoid using null, and simply change the value to empty string
dateRef.current = '';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.