--- id: reactivity title: Reactivity --- Tanstack Form doesn't cause re-renders when interacting with the form. So, you might find yourself trying to use a form or field state value without success. If you would like to access reactive values, you will need to subscribe to them using one of two methods: `useSelector` or the `form.Subscribe` component. Some uses for these subscriptions are rendering up-to-date field values, determining what to render based on a condition, or using field values inside the logic of your component. > For situations where you want to "react" to triggers, check out the [listener](./listeners.md) API. ## useSelector The `useSelector` hook is perfect when you need to access form values within the logic of your component. Import it from `@tanstack/react-form`. It takes the form store as its first argument and a selector as its second. ```tsx import { useSelector } from '@tanstack/react-form' const firstName = useSelector(form.store, (state) => state.values.firstName) const errors = useSelector(form.store, (state) => state.errorMap) ``` You can access any piece of the form state in the selector. > Note, that `useSelector` will cause a whole component re-render whenever the value subscribed to changes. While it IS possible to omit the selector, resist the urge as omitting it would result in many unnecessary re-renders whenever any of the form state changes. > **Migration:** `useStore` is still exported but deprecated (it is an alias from `@tanstack/react-store`). Replace `useStore` with `useSelector` — same arguments, or pass `{ compare }` as the third argument instead of a bare `compare` function. ## form.Subscribe The `form.Subscribe` component is best suited when you need to react to something within the UI of your component. For example, showing or hiding UI based on the value of a form field. ```tsx state.values.firstName} children={(firstName) => ( {(field) => ( )} )} /> ``` > The `form.Subscribe` component doesn't trigger component-level re-renders. Anytime the value subscribed to changes, only the `form.Subscribe` component re-renders. The choice between whether to use `useSelector` or `form.Subscribe` mainly boils down to your use case. If you're aiming for direct UI updates based on form state, use `form.Subscribe` for its optimization perks. And if you need the reactivity within the logic, then `useSelector` is the better choice. ## Field state Inside a field, you don't need `useSelector` or `form.Subscribe` to read the field's own state. `form.Field` subscribes to its field for you: its render function runs again whenever the field's value or meta (such as `isTouched`, `isDirty`, `errors` or `isValidating`) changes, so `field.state.value` and `field.state.meta` are up to date there. > [!NOTE] > Array fields (`mode="array"`) are an exception: to avoid re-rendering the whole list on every keystroke, they don't re-render when a value inside one of their items changes. Render those values with their own `form.Field` instead. Field components that read the field with `useFieldContext`, as shown in [Form Composition](./form-composition.md#pre-bound-field-components), live outside that render function. In those components, read field state such as `meta` with `useSelector` and the field's store: ```tsx import { useSelector } from '@tanstack/react-form' const errors = useSelector(field.store, (state) => state.meta.errors) ```