Skip to content

Commit 1932c0a

Browse files
authored
Merge pull request #32 from byondrnd/usehandler-update
update useHandler
2 parents 7391001 + cd2a4bd commit 1932c0a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

.changeset/pink-squids-allow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@byondxr/react-utils": patch
3+
---
4+
5+
useHandler update

packages/react-utils/src/index.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, memo as reactMemo, useRef } from 'react'
1+
import { useCallback, memo as reactMemo, useRef, useState } from 'react'
22
import type { Dict, EmptyDict } from '@byondxr/utils'
33
import type { DependencyList, FunctionComponent, Key, NamedExoticComponent, ReactNode } from 'react'
44

@@ -13,12 +13,9 @@ const _useCallback = useCallback
1313
export const useHandler: UseHandler = <T extends Function>(callback: T): T => {
1414
const callbackRef = useRef(callback)
1515
callbackRef.current = callback
16-
// useUnmount(() => {
17-
// // making sure that whoever used that function will not keep it in scope in order to clean memory (for recoil selector)
18-
// callbackRef.current = (() => {}) as any
19-
// })
20-
21-
return _useCallback((...args: any[]) => callbackRef.current(...args), []) as unknown as T
16+
return useState(() => {
17+
return ((...args: any[]) => callbackRef.current(...args)) as unknown as T
18+
})[0]
2219
}
2320

2421
type UseInlineHandler = () => {

0 commit comments

Comments
 (0)