docs(react): document field state reactivity #2445
Mergeddgesteves(GitHub profile, opens in a new tab)merged 3 commits into
main fromrefs/pull/2445/headmerged by LeCarbonator(GitHub profile, opens in a new tab) LeCarbonator(GitHub profile, opens in a new tab) requested changes
docs/framework/react/guides/reactivity.md line 62OutdatedResolvedby dgesteves(GitHub profile, opens in a new tab)@@ -54,3 +54,9 @@5454 The `form.Subscribe` component doesn't trigger component-level re-renders. Anytime the value subscribed to changes, only the `form.Subscribe` component re-renders.55555656 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.57+58+## Field state59+60+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.61+62+The same applies to field components that read the field with `useFieldContext`, as shown in [Form Composition](./form-composition.md#pre-bound-field-components). Even though they live outside the render function, they re-render together with the field, so they can read `field.state.value` and `field.state.meta` directly.docs/framework/react/guides/reactivity.md line 63Resolvedby dgesteves(GitHub profile, opens in a new tab)@@ -54,3 +54,11 @@5454 The `form.Subscribe` component doesn't trigger component-level re-renders. Anytime the value subscribed to changes, only the `form.Subscribe` component re-renders.55555656 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.57+58+## Field state59+60+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.61+62+The same applies to field components that read the field with `useFieldContext`, as shown in [Form Composition](./form-composition.md#pre-bound-field-components). Even though they live outside the render function, they re-render together with the field, so they can read `field.state.value` and `field.state.meta` directly.63+64+ 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.LeCarbonator(GitHub profile, opens in a new tab) approved these changes
LeCarbonator(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
⚠️ No Changeset found#
Latest commit: ebdd2bc4b2e60f5fd5c8cc65e3d0b82fc9581b98
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR