You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/framework/react/guides/ui-libraries.md
+67-35Lines changed: 67 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,16 +5,17 @@ title: UI Libraries
5
5
6
6
## Usage of TanStack Form with UI Libraries
7
7
8
-
TanStack Form is a headless library, offering you complete flexibility to style it as you see fit. It's compatible with a wide range of UI libraries, including `Tailwind`, `Material UI`, `Mantine`, or even plain CSS.
8
+
TanStack Form is a headless library, offering you complete flexibility to style it as you see fit. It's compatible with a wide range of UI libraries, including `Tailwind`, `Material UI`, `Mantine`, `shadcn/ui`, or even plain CSS.
9
9
10
-
This guide focuses on `Material UI`and `Mantine`, but the concepts are applicable to any UI library of your choice.
10
+
This guide focuses on `Material UI`, `Mantine`, and `shadcn/ui`, but the concepts are applicable to any UI library of your choice.
11
11
12
12
### Prerequisites
13
13
14
14
Before integrating TanStack Form with a UI library, ensure the necessary dependencies are installed in your project:
15
15
16
16
- For `Material UI`, follow the installation instructions on their [official site](https://mui.com/material-ui/getting-started/).
17
17
- For `Mantine`, refer to their [documentation](https://mantine.dev/).
18
+
- For `shadcn/ui`, refer to their [official site](https://ui.shadcn.com/).
18
19
19
20
Note: While you can mix and match libraries, it's generally advisable to stick with one to maintain consistency and minimize bloat.
20
21
@@ -29,8 +30,7 @@ import { useForm } from '@tanstack/react-form'
- Initially, we utilize the `useForm` hook from TanStack and destructure the necessary properties. This step is optional; alternatively, you could use `const form = useForm()` if preferred. TypeScript's type inference ensures a smooth experience regardless of the approach.
81
81
- The `Field` component, derived from `useForm`, accepts several properties, such as `validators`. For this demonstration, we focus on two primary properties: `name` and `children`.
82
-
- The `name` property identifies each `Field`, for instance, `firstName` in our example.
82
+
- The `name` property identifies each `Field`, for instance, `name` in our example.
83
83
- The `children` property leverages the concept of render props, allowing us to integrate components without unnecessary abstractions.
84
84
- TanStack's design relies heavily on render props, providing access to `children` within the `Field` component. This approach is entirely type-safe. When integrating with Mantine components, such as `TextInput`, we selectively destructure properties like `state.value`, `handleChange`, and `handleBlur`. This selective approach is due to the slight differences in types between `TextInput` and the `field` we get in the children.
85
85
- By following these steps, you can seamlessly integrate Mantine components with TanStack Form.
@@ -90,37 +90,69 @@ export default function App() {
90
90
The process for integrating Material UI components is similar. Here's an example using TextField and Checkbox from Material UI:
0 commit comments