i’m using React, Node.js(express.js), PostgreSQL. I want to use validation with react-hook-form library. before i use it, i could change date. but i add the code i couldn’t change the date. what is my false? How can i change the data, using react-hook-form library. Thanks for your effort in advance.
the code that i can’t change the date.
import { useState, useEffect, useRef } from "react";
import { useForm } from "react-hook-form";
const [startDate, setStartDate] = useState(formattedDate);
const handleStartDateChange = (e) => {
setStartDate(e.target.value);
};
<input
type="date"
id="startDate"
value={startDate}
onChange={handleStartDateChange}
className="form-control"
{...register("startDate", { required: true })}
dateformat="yyyy-MM-dd"
style={{
width: "100%",
maxWidth: "9rem",
color: "#212529",
fontSize: "16px",
fontFamily: "auto",
}}
onClick={(e) => e.target.showPicker()}
/>
the code which i can change date.
import { useState, useEffect, useRef } from "react";
import { useForm } from "react-hook-form";
const [startDate, setStartDate] = useState(formattedDate);
const handleStartDateChange = (e) => {
setStartDate(e.target.value);
};
<input
type="date"
id="startDate"
value={startDate}
onChange={handleStartDateChange}
className="form-control"
dateformat="yyyy-MM-dd"
style={{
width: "100%",
maxWidth: "9rem",
color: "#212529",
fontSize: "16px",
fontFamily: "auto",
}}
onClick={(e) => e.target.showPicker()}
/>
I want to change the date using validation function with react-hook-form
전승민 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.