mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-21 06:40:33 +01:00
15 lines
337 B
TypeScript
15 lines
337 B
TypeScript
import { useEffect, useRef } from 'react';
|
|
|
|
/**
|
|
* Returns first only when rendered for the first time
|
|
* and subsequent always after that
|
|
*/
|
|
export const useOnce = <T>(first: T, subsequent: T) => {
|
|
const ref = useRef(first);
|
|
useEffect(() => {
|
|
ref.current = subsequent;
|
|
}, [subsequent]);
|
|
|
|
return ref.current;
|
|
};
|