npm install react-hook-form
아래 간단한 예시를 만들어 보았습니다.
import "./styles.css";
import React from "react";
import { useForm } from "react-hook-form";
export default function App() {
return (
<div className="App">
<h1>React Hook Form 예시</h1>
</div>
);
}
import "./styles.css";
import React from "react";
import { useForm } from "react-hook-form";
export default function App() {
return (
<div className="App">
<h1>React Hook Form 예시</h1>
<form>
</form>
</div>
);
}
import "./styles.css";
import React from "react";
import { useForm } from "react-hook-form";
export default function App() {
return (
<div className="App">
<h1>React Hook Form 예시</h1>
<form>
<input/>
<select>
<option value="female">여성</option>
<option value="male">남성</option>
<option value="other">기타</option>
</select>
<input type="submit" />
</form>
</div>
);
}
import "./styles.css";
import React from "react";
import { useForm } from "react-hook-form";
export default function App() {
const { register, handleSubmit } = useForm();
return (
<div className="App">
<h1>React Hook Form 예시</h1>
<form>
<input />
<select>
<option value="female">여성</option>
<option value="male">남성</option>
<option value="other">기타</option>
</select>
<input type="submit" />
</form>
</div>
);
}
import "./styles.css";
import React from "react";
import { useForm } from "react-hook-form";
export default function App() {
const { register, handleSubmit } = useForm();
const onSubmit = (data) => console.log(data);
return (
<div className="App">
<h1>React Hook Form 예시</h1>
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register("firstName")} />
<select {...register("gender")}>
<option value="female">여성</option>
<option value="male">남성</option>
<option value="other">기타</option>
</select>
<input type="submit" />
</form>
</div>
);
}