What is @hookform/devtools?
@hookform/devtools is a development tool for React Hook Form, which provides a visual interface to debug and inspect forms created with React Hook Form. It helps developers to see the form state, errors, and other useful information in real-time.
What are @hookform/devtools's main functionalities?
Visual Form State Inspection
This feature allows developers to visually inspect the form state, including values, errors, and touched fields. The DevTool component is integrated into the form and provides a real-time view of the form's state.
import { DevTool } from '@hookform/devtools';
import { useForm } from 'react-hook-form';
function MyForm() {
const { control, handleSubmit } = useForm();
const onSubmit = data => console.log(data);
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input name="firstName" ref={control.register} />
<input name="lastName" ref={control.register} />
<button type="submit">Submit</button>
<DevTool control={control} />
</form>
);
}
Error Debugging
This feature helps in debugging form errors by providing a visual representation of the errors in the form. The DevTool component shows the errors in real-time, making it easier to identify and fix issues.
import { DevTool } from '@hookform/devtools';
import { useForm } from 'react-hook-form';
function MyForm() {
const { control, handleSubmit, errors } = useForm();
const onSubmit = data => console.log(data);
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input name="firstName" ref={control.register({ required: true })} />
{errors.firstName && <span>This field is required</span>}
<input name="lastName" ref={control.register({ required: true })} />
{errors.lastName && <span>This field is required</span>}
<button type="submit">Submit</button>
<DevTool control={control} />
</form>
);
}
Real-time Form Updates
This feature allows developers to see real-time updates of the form state as users interact with the form. The DevTool component provides a live view of the form's state, making it easier to track changes and debug issues.
import { DevTool } from '@hookform/devtools';
import { useForm } from 'react-hook-form';
function MyForm() {
const { control, handleSubmit, watch } = useForm();
const onSubmit = data => console.log(data);
const firstName = watch('firstName');
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input name="firstName" ref={control.register} />
<input name="lastName" ref={control.register} />
<p>First Name: {firstName}</p>
<button type="submit">Submit</button>
<DevTool control={control} />
</form>
);
}
Other packages similar to @hookform/devtools
redux-devtools
Redux DevTools is a development tool for Redux that provides a visual interface to inspect and debug Redux state changes. It offers similar functionalities to @hookform/devtools but is focused on Redux state management rather than form state.
react-query-devtools
React Query DevTools is a development tool for React Query that provides a visual interface to inspect and debug queries and mutations. It offers similar functionalities to @hookform/devtools but is focused on data fetching and caching rather than form state.
mobx-react-devtools
MobX React DevTools is a development tool for MobX that provides a visual interface to inspect and debug MobX state changes. It offers similar functionalities to @hookform/devtools but is focused on MobX state management rather than form state.
Performant, flexible and extensible forms with easy to use validation.
Goal
This React Component will help you to debug forms when working React Hook Form, and give you more insight about your form's detail.
Install
$ npm install @hookform/devtools -D
Quickstart
import React from 'react';
import { useForm } from 'react-hook-form';
import { DevTool } from '@hookform/devtools';
import './App.css';
const App = () => {
const { register, control, handleSubmit } = useForm({
mode: 'onChange',
});
return (
<>
<DevTool control={control} placement="top-left" />
<form onSubmit={handleSubmit((d) => console.log(d))}>
<h1>React Hook Form DevTools</h1>
<label>Test</label>
<input name="test" ref={register} />
<input type="submit" />
</form>
</>
);
};
export default App;
Backers
Thanks goes to all our backers! [Become a backer].
Organizations
Thanks goes to these wonderful organizations! [Contribute].
Contributors
Thanks goes to these wonderful people! [Become a contributor].