Skip to content

docs: clarify that useStore selector is required#2080

Open
dkpark10 wants to merge 1 commit intoTanStack:mainfrom
dkpark10:docs/reactivity-usestore-selector
Open

docs: clarify that useStore selector is required#2080
dkpark10 wants to merge 1 commit intoTanStack:mainfrom
dkpark10:docs/reactivity-usestore-selector

Conversation

@dkpark10
Copy link

@dkpark10 dkpark10 commented Mar 13, 2026

🎯 Changes

#2035
Update the documentation to reflect that the useStore selector parameter is required.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • [] I have tested this code locally with pnpm test:pr.

🚀 Release Impact

  • [] This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2026

⚠️ No Changeset found

Latest commit: 76cbecd

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

@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

📝 Walkthrough

Walkthrough

Documentation clarification for the useStore hook in React guides: the selector parameter is now described as required rather than optional. The guidance shifts from permitting selector omission (which could cause unnecessary re-renders) to enforcing it as a necessity for subscribing to specific state slices.

Changes

Cohort / File(s) Summary
Documentation Update
docs/framework/react/guides/reactivity.md
Updated guidance for useStore selector parameter from optional to required, emphasizing its role in avoiding unnecessary re-renders when subscribing to specific portions of form state.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

A selector's not optional, dear reviewer, can't you see? ✨
It's the key to subscription, to reactivity's decree!
No more whispered warnings of renders gone astray,
The guidance shines clearer now—this is the way! 🐰

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main change: clarifying that the useStore selector parameter is required.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description follows the repository template with all major sections completed, including motivation, checklist, and release impact classification.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/framework/react/guides/reactivity.md`:
- Line 27: The docs incorrectly state that the selector parameter is required;
update the text to say the selector is optional (signature uses selector?:) and
that it defaults to (state) => state, recommending its use for performance to
subscribe only to needed parts of form state; replace the sentence "The selector
parameter is required..." with wording that it is optional but recommended and
mention the default selector function and purpose (avoid unnecessary
re-renders).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cd1b8dbc-c120-45cf-ab39-25fe85740b72

📥 Commits

Reviewing files that changed from the base of the PR and between 3f52569 and 76cbecd.

📒 Files selected for processing (1)
  • docs/framework/react/guides/reactivity.md

> Note, that `useStore` 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.
The selector parameter is required. It allows you to subscribe to only the specific part of the form state your component needs, helping avoid unnecessary re-renders when other parts of the state change.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check the TypeScript signature of useStore to confirm if selector is required or optional

# Search for useStore function/hook definition
ast-grep --pattern $'export function useStore($$$) {
  $$$
}'

# Also search for useStore type declarations
rg -nP --type=ts -C5 'function useStore|export.*useStore'

# Check for LocalSubscribe which wraps useStore
rg -nP --type=ts -C3 'function LocalSubscribe'

Repository: TanStack/form

Length of output: 2673


🏁 Script executed:

# Check if `@tanstack/react-store` is in the packages directory
fd -t d "react-store" packages/

# If it's an external package, search for useStore definition in node_modules or find where it's defined
find packages -name "*react-store*" -o -name "*store*" | head -20

# Search for any TypeScript definition files mentioning useStore signature
rg -t ts "export.*function useStore|export.*useStore.*=" --max-count=10

Repository: TanStack/form

Length of output: 98


🏁 Script executed:

# List all packages to find react-store
ls -la packages/ | grep -i store

# Search for type definitions of useStore
rg -t ts "selector\?" packages/ --max-count=20

# Look for .d.ts files that might have type signatures
fd -t f "\.d\.ts$" packages/ -x grep -l "useStore" {}

# Check package.json to understand the structure
find packages -name "package.json" -exec grep -l "react-store" {} \;

Repository: TanStack/form

Length of output: 1108


🏁 Script executed:

# Read the documentation file to see line 27 and surrounding context
sed -n '20,35p' docs/framework/react/guides/reactivity.md

# Also check if there's a useStore definition in react-store package if it exists locally
find packages -name "react-store" -type d

Repository: TanStack/form

Length of output: 773


The selector parameter is optional, not required.

The documentation claims the selector parameter is required, but the implementation across all form frameworks (React, Vue, Svelte, Solid, Angular) defines it as optional with selector?: and provides a default value (state) => state. Update the documentation to reflect that the selector parameter is optional but recommended for performance optimization.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/framework/react/guides/reactivity.md` at line 27, The docs incorrectly
state that the selector parameter is required; update the text to say the
selector is optional (signature uses selector?:) and that it defaults to (state)
=> state, recommending its use for performance to subscribe only to needed parts
of form state; replace the sentence "The selector parameter is required..." with
wording that it is optional but recommended and mention the default selector
function and purpose (avoid unnecessary re-renders).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant