Capítulo 21 de 29

Chapter 21: React Native

Core Idea

No special configuration is needed for React Native — the library is headless enough that TextInput/Text wire up through the exact same form.Field render-prop pattern as any web <input>.

Key Concepts

  • The docs describe React Native support as working "out-of-the-box" — there is no @tanstack/react-native-form package; the standard @tanstack/react-form is used directly.
  • Field wiring is identical to web: field.state.value, field.handleChange, and error display via field.state.meta.errors, just bound to TextInput.onChangeText instead of an <input>'s onChange.
  • The one documented React Native-specific caveat lives in ch019 (Focus Management): no document.querySelector, so focus-on-error requires manual ref tracking.

Code Examples

<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.isValid && <Text>{field.state.meta.errors.join(', ')}</Text>}
    </>
  )}
</form.Field>
  • What it demonstrates: the same validated-field shape as every other chapter, just bound to React Native's TextInput/onChangeText instead of DOM equivalents.

Key Takeaways

  1. Don't look for a separate React Native package — @tanstack/react-form itself is the one to install.
  2. The only real divergence from web usage is event-prop naming (onChangeText vs onChange) — validators, listeners, arrays, and composition patterns from every other chapter apply unchanged.
  3. Budget for manual focus-management work (ch019) specifically because React Native has no DOM to query.

Connects To

  • Ch019 Focus Management: the one documented React-Native-specific gap.
  • Ch006 React Quick Start: the web equivalent of this same minimal pattern.