Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

quick-start.md

56 lines1.4 KB

1---
2id: quick-start
3title: Quick Start
4---
5​
6The bare minimum to get started with TanStack Form is to create a form and add a field. Keep in mind that this example does not include any validation or error handling... yet.
7​
8```tsx
9import React from 'react'
10import ReactDOM from 'react-dom/client'
11import { useForm } from '@tanstack/react-form'
12​
13export default function App() {
14 const form = useForm({
15 defaultValues: {
16 fullName: '',
17 },
18 onSubmit: async ({ value }) => {
19 // Do something with form data
20 console.log(value)
21 },
22 })
23​
24 return (
25 <div>
26 <form
27 onSubmit={(e) => {
28 e.preventDefault();
29 e.stopPropagation();
30 form.handleSubmit();
31 }}
32 >
33 <div>
34 <form.Field
35 name="fullName"
36 children={(field) => (
37 <input
38 name={field.name}
39 value={field.state.value}
40 onBlur={field.handleBlur}
41 onChange={(e) => field.handleChange(e.target.value)}
42 />
43 )}
44 />
45 </div>
46 <button type="submit">Submit</button>
47 </form>
48 </div>
49 )
51​
52const rootElement = document.getElementById('root')!
53ReactDOM.createRoot(rootElement).render(<App />)
54```
55​
56From here, you'll be ready to explore all of the other features of TanStack Form!