Skip to content

Commit

Permalink
fix: useSyncExternalStore backward compatibility (#296)
Browse files Browse the repository at this point in the history
Co-authored-by: paco <34928425+pacocoursey@users.noreply.github.com>
  • Loading branch information
MateoKruk and pacocoursey authored Oct 30, 2024
1 parent 503b2c2 commit 0bd1fe2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion cmdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"dependencies": {
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-id": "^1.1.0",
"@radix-ui/react-primitive": "^2.0.0"
"@radix-ui/react-primitive": "^2.0.0",
"use-sync-external-store": "^1.2.2"
},
"devDependencies": {
"@types/react": "18.0.15"
Expand Down
3 changes: 2 additions & 1 deletion cmdk/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from 'react'
import { commandScore } from './command-score'
import { Primitive } from '@radix-ui/react-primitive'
import { useId } from '@radix-ui/react-id'
import { useSyncExternalStore } from 'use-sync-external-store'

type Children = { children?: React.ReactNode }
type DivProps = React.ComponentPropsWithoutRef<typeof Primitive.div>
Expand Down Expand Up @@ -1013,7 +1014,7 @@ function mergeRefs<T = any>(refs: Array<React.MutableRefObject<T> | React.Legacy
function useCmdk<T = any>(selector: (state: State) => T) {
const store = useStore()
const cb = () => selector(store.snapshot())
return React.useSyncExternalStore(store.subscribe, cb, cb)
return useSyncExternalStore(store.subscribe, cb, cb)
}

function useValue(
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0bd1fe2

Please sign in to comment.