From 51a75556a15a200b86a41ed7486957b49291d40c Mon Sep 17 00:00:00 2001 From: Maks Pikov Date: Sun, 15 Mar 2026 22:27:10 +0000 Subject: [PATCH 1/2] fix(react-form): restore optional selector in useStore re-export 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 #2074 --- packages/react-form/src/index.ts | 2 +- packages/react-form/src/useStore.ts | 44 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 packages/react-form/src/useStore.ts diff --git a/packages/react-form/src/index.ts b/packages/react-form/src/index.ts index e032da0e2..c5878a608 100644 --- a/packages/react-form/src/index.ts +++ b/packages/react-form/src/index.ts @@ -1,6 +1,6 @@ export * from '@tanstack/form-core' -export { useStore } from '@tanstack/react-store' +export { useStore } from './useStore' export * from './createFormHook' export * from './types' diff --git a/packages/react-form/src/useStore.ts b/packages/react-form/src/useStore.ts new file mode 100644 index 000000000..66db6423c --- /dev/null +++ b/packages/react-form/src/useStore.ts @@ -0,0 +1,44 @@ +import { useStore as _useStore } from '@tanstack/react-store' +import type { AnyAtom } from '@tanstack/store' + +type AtomSnapshot = TAtom extends { get: () => infer TSnapshot } + ? TSnapshot + : undefined + +/** + * Subscribe to a store atom and return its current state. + * + * When called without a `selector` the full atom snapshot is returned. + * + * @example + * // Return the full form state (selector optional for back-compat) + * const formState = useStore(form.store) + * + * @example + * // Return a specific slice + * const isValid = useStore(form.store, (s) => s.isValid) + */ +export function useStore( + atom: TAtom, +): AtomSnapshot + +export function useStore( + atom: TAtom, + selector: (snapshot: AtomSnapshot) => T, + compare?: (a: T, b: T) => boolean, +): T + +export function useStore( + atom: TAtom, + selector?: (snapshot: AtomSnapshot) => T, + compare?: (a: T, b: T) => boolean, +): T | AtomSnapshot { + // When no selector is provided fall back to the identity function so that + // callers that were using `useStore(form.store)` without a selector + // (as was valid in prior releases) continue to work. + return _useStore( + atom, + (selector ?? ((s: any) => s)) as (snapshot: AtomSnapshot) => T, + compare, + ) +} From 68b42a65a5cb286b4f0d240baadb87f25c90080a Mon Sep 17 00:00:00 2001 From: Maks Pikov Date: Wed, 18 Mar 2026 01:04:28 +0000 Subject: [PATCH 2/2] fix(react-form): import AnyAtom from @tanstack/react-store instead of @tanstack/store --- packages/react-form/src/useStore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-form/src/useStore.ts b/packages/react-form/src/useStore.ts index 66db6423c..34276c73a 100644 --- a/packages/react-form/src/useStore.ts +++ b/packages/react-form/src/useStore.ts @@ -1,5 +1,5 @@ import { useStore as _useStore } from '@tanstack/react-store' -import type { AnyAtom } from '@tanstack/store' +import type { AnyAtom } from '@tanstack/react-store' type AtomSnapshot = TAtom extends { get: () => infer TSnapshot } ? TSnapshot