Skip to content

fix(react-form): restore optional selector in re-exported useStore#2083

Open
mixelburg wants to merge 1 commit intoTanStack:mainfrom
mixelburg:fix/useStore-selector-optional
Open

fix(react-form): restore optional selector in re-exported useStore#2083
mixelburg wants to merge 1 commit intoTanStack:mainfrom
mixelburg:fix/useStore-selector-optional

Conversation

@mixelburg
Copy link

@mixelburg mixelburg commented Mar 15, 2026

Summary

Fixes #2074

Problem

Prior to @tanstack/react-store@0.9.1, useStore could be called with just a store reference:

const formState = useStore(form.store) // ✅ worked before

The 0.9.1 update to react-store made the selector argument required in its TypeScript types. Because @tanstack/react-form re-exported useStore directly:

export { useStore } from '@tanstack/react-store'

…any project that had previously used the single-argument form now sees a TypeScript build error:

error TS2554: Expected 2-3 arguments, but got 1.

Fix

Instead of re-exporting useStore verbatim, this PR adds a thin overload wrapper in packages/react-form/src/useStore.ts that:

  1. No selector – returns the full atom snapshot (restores pre-1.28.4 behaviour)
  2. With selector – passes through to the underlying @tanstack/react-store implementation

At runtime the identity function (s) => s is used as the default selector, which matches what the underlying implementation would have done before.

Summary by CodeRabbit

  • Refactor
    • Enhanced the useStore hook with improved type safety and better support for custom selectors and comparison functions.

Prior to @tanstack/react-store 0.9.1, useStore could be called with just
a store reference and no selector, which returned the full atom snapshot:

  const formState = useStore(form.store)

The 0.9.1 update made the selector argument required in TypeScript types,
causing a build error in existing code using the single-argument form.

Instead of re-exporting useStore directly, add a thin overload wrapper in
packages/react-form/src/useStore.ts that makes the selector optional and
preserves backward-compatible types while delegating to the underlying
@tanstack/react-store implementation.

Fixes TanStack#2074
@changeset-bot
Copy link

changeset-bot bot commented Mar 15, 2026

⚠️ No Changeset found

Latest commit: 51a7555

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 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7c380447-0611-4264-b09f-942c888bca47

📥 Commits

Reviewing files that changed from the base of the PR and between b1bf05d and 51a7555.

📒 Files selected for processing (2)
  • packages/react-form/src/index.ts
  • packages/react-form/src/useStore.ts

📝 Walkthrough

Walkthrough

A local useStore wrapper is introduced in the react-form package, replacing the direct re-export from @tanstack/react-store. The wrapper adds TypeScript overloads to support optional selector parameters, enabling flexible usage patterns while maintaining type safety.

Changes

Cohort / File(s) Summary
Export Source Migration
packages/react-form/src/index.ts
Modified public export of useStore to source from local ./useStore module instead of @tanstack/react-store.
Type-Safe Hook Wrapper
packages/react-form/src/useStore.ts
New file introducing a local useStore hook with TypeScript overloads: accepts atom alone (returns snapshot), or atom with optional selector/compare functions (returns selected value). Includes AtomSnapshot<TAtom> type utility for snapshot type extraction. Implementation delegates to the upstream _useStore with identity selector as default.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A wrapper so neat, with types crystal clear,
No more selector woes, the API's sincere!
One arg or three, we handle them all,
Type safety and joy, now standing tall! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: restoring the optional selector functionality to the re-exported useStore hook.
Description check ✅ Passed The description provides a comprehensive explanation of the problem, solution, and implementation details, though it does not include the checklist items from the template.
Linked Issues check ✅ Passed The code changes directly address issue #2074 by restoring the optional selector overload in useStore, allowing single-argument calls like useStore(form.store) to compile without TypeScript errors.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the useStore export and restoring backward-compatible overloads; no unrelated modifications are present.

✏️ 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.

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.

Type error in useStore when upgrading from 1.28.0 to 1.28.4

1 participant