Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chatty-humans-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/react-store': patch
---

fix(react): use Object.is instead of === in defaultCompare to correctly handle NaN and -0 edge cases
1 change: 1 addition & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:
permissions:
contents: read
pull-requests: write
issues: write

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion docs/framework/react/reference/functions/useStore.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function useStore<TAtom, T>(
compare): T;
```

Defined in: [useStore.ts:13](https://github.com/TanStack/store/blob/main/packages/react-store/src/useStore.ts#L13)
Defined in: [useStore.ts:14](https://github.com/TanStack/store/blob/main/packages/react-store/src/useStore.ts#L14)

## Type Parameters

Expand Down
3 changes: 2 additions & 1 deletion packages/react-store/src/useStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ type SyncExternalStoreSubscribe = Parameters<
typeof useSyncExternalStoreWithSelector
>[0]

/** Comparator using Object.is to correctly handle NaN and -0 edge cases. */
function defaultCompare<T>(a: T, b: T) {
return a === b
return Object.is(a, b)
}

export function useStore<TAtom extends AnyAtom | undefined, T>(
Expand Down