Skip to content

Instantly share code, notes, and snippets.

View hshoja's full-sized avatar
🚀
Coding | Learning | Building

Hamid Shoja hshoja

🚀
Coding | Learning | Building
View GitHub Profile
@hshoja
hshoja / useEventCallback.ts
Created October 5, 2025 11:52
useEventCallback
import * as React from 'react'
export const canUseDom = !!(typeof window !== 'undefined' && window.document && window.document.createElement)
export const useIsomorphicLayoutEffect = Runtime.canUseDom ? React.useLayoutEffect : React.useEffect
export function useEventCallback<T extends (...args: any[]) => any>(fn: T): T {
const ref: any = React.useRef(fn)
useIsomorphicLayoutEffect(() => {