I have this component in my react js application:
import * as React from "react";
import * as ReactDOM from "react-dom";
import { useForm } from "react-hook-form";
import "./styles.css";
const App = () => {
const {
register,
handleSubmit,
setValue,
formState: { errors }
} = useForm({
defaultValues: {
firstName: "",
lastName: "luo",
amount: ""
}
});
const onSubmit = (data) => {
// alert(JSON.stringify(data));
};
console.log(JSON.stringify(errors), "f");
return (
<form onSubmit={handleSubmit(onSubmit)}>
<label>First Name</label>
<input type="text" {...register("firstName", { required: true })} />
<input type="submit" />
</form>
);
};
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
When i click on submit i get the next issue: Uncaught TypeError: cyclic object value
, this happens because of using JSON stringify.
Question : Why i get this issue in my code and how to use JSON.stringify and to get rid of the issue?
demo: https://codesandbox.io/s/react-hook-form-get-started-ts-forked-wfzjyr?file=/src/index.tsx:0-776