Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: useCallbackRef now actually works #8133

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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/itchy-fireants-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chakra-ui/react-use-callback-ref": patch
---

fix: useCallbackRef now actually works
10 changes: 3 additions & 7 deletions packages/hooks/use-callback-ref/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { useCallback, useEffect, useRef } from "react"
import { useCallback, useRef } from "react"

export function useCallbackRef<T extends (...args: any[]) => any>(
callback: T | undefined,
deps: React.DependencyList = [],

Check failure on line 5 in packages/hooks/use-callback-ref/src/index.ts

View workflow job for this annotation

GitHub Actions / ESLint

'deps' is assigned a value but never used
) {
const callbackRef = useRef(callback)
callbackRef.current = callback

useEffect(() => {
callbackRef.current = callback
})

// eslint-disable-next-line react-hooks/exhaustive-deps
return useCallback(((...args) => callbackRef.current?.(...args)) as T, deps)
return useCallback(((...args) => callbackRef.current?.(...args)) as T, [])

Check failure on line 10 in packages/hooks/use-callback-ref/src/index.ts

View workflow job for this annotation

GitHub Actions / ESLint

React Hook useCallback received a function whose dependencies are unknown. Pass an inline function instead
}
Loading