import React from "react"; import ReactDOM from "react-dom"; import useForm from "react-hook-form"; const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); function App() { const { register, handleSubmit, errors } = useForm(); const onSubmit = async data => { await sleep(2000); if (data.username === "bill") { alert(JSON.stringify(data)); } else { alert("There is error"); } }; console.log(errors); return (
{Object.keys(errors).length > 0 && "There are errors, check your console."}
); } const rootElement = document.getElementById("root"); ReactDOM.render(, rootElement);