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

quick-start.md

52 lines1.2 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 { createForm } from '@tanstack/solid-form'
10​
11function App() {
12 const form = createForm(() => ({
13 defaultValues: {
14 fullName: '',
15 },
16 onSubmit: async ({ value }) => {
17 // Do something with form data
18 console.log(value)
19 },
20 }))
21​
22 return (
23 <div>
24 <h1>Simple Form Example</h1>
25 <form
26 onSubmit={(e) => {
27 e.preventDefault()
28 e.stopPropagation()
29 form.handleSubmit()
30 }}
31 >
32 <div>
33 <form.Field
34 name="fullName"
35 children={(field) => (
36 <input
37 name={field().name}
38 value={field().state.value}
39 onBlur={field().handleBlur}
40 onInput={(e) => field().handleChange(e.target.value)}
41 />
42 )}
43 />
44 </div>
45 <button type="submit">Submit</button>
46 </form>
47 </div>
48 )
50```
51​
52From here, you'll be ready to explore all of the other features of TanStack Form!