mirror of
https://github.com/logto-io/logto.git
synced 2025-02-03 21:48:55 -05:00
15 lines
301 B
TypeScript
15 lines
301 B
TypeScript
import { useEffect, useState } from 'react';
|
|
|
|
const useCacheValue = <T>(value: T) => {
|
|
const [cachedValue, setCachedValue] = useState<T>();
|
|
|
|
useEffect(() => {
|
|
if (value !== undefined) {
|
|
setCachedValue(value);
|
|
}
|
|
}, [value]);
|
|
|
|
return cachedValue;
|
|
};
|
|
|
|
export default useCacheValue;
|