Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update react-native.md #1293

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions docs/framework/react/guides/react-native.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,36 @@ TanStack Form is headless and it should support React Native out-of-the-box with
Here is an example:

```tsx
<form.Field
name="age"
validators={{
onChange: (val) =>
val < 13 ? 'You must be 13 to make an account' : undefined,
}}
>
{(field) => (
<>
<Text>Age:</Text>
<TextInput value={field.state.value} onChangeText={field.handleChange} />
{field.state.meta.errors ? (
<Text>{field.state.meta.errors.join(', ')}</Text>
) : null}
</>
)}
</form.Field>
import { Text, View, TextInput } from 'react-native';
import { useForm } from "@tanstack/react-form";


export default function App() {
//Doesnt work even if changed to "Form" instead of "form"
const form = useForm({
defaultValues: {
name: "",
},
onSubmit: async ({ value }) => {
// Do something with form data
console.log(value);
},
});
return (
<View style={{ flex: 1 }}>
<form.Field
name="name"
children={(field) => (
<Text>Enter a name!</Text>
<TextInput
value={field.state.value}
onBlur={field.handleBlur}
onChangeText={(e) => field.handleChange(e)}
/>
)}
/>
</View>
);
}

```