summaryrefslogtreecommitdiff
path: root/apps/web/src/hooks/use-committed-ref.ts
blob: ff0649851f736a5479e44de6cea482f46571a824 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
import { useLayoutEffect, useRef } from "react";

export function useCommittedRef<T>(value: T) {
	const ref = useRef(value);

	useLayoutEffect(() => {
		ref.current = value;
	}, [value]);

	return ref;
}