Skip to content

Instantly share code, notes, and snippets.

View MarekZeman91's full-sized avatar
๐Ÿ˜

Marek Zeman MarekZeman91

๐Ÿ˜
  • Marek Zeman
  • Czech Republic
View GitHub Profile
@MarekZeman91
MarekZeman91 / useFunction.ts
Last active October 30, 2025 21:45
React hook that allows you to have always up-to-date function without re-render trigger.
import { useCallback } from 'react';
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
export function useFunction<T extends Function>(fn: T): T {
const hook = useCallback<any>(function (this: any, ...args: any[]) {
return hook.fn.apply(this, args);
}, []);
hook.fn = fn;
return hook as T;
}