mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-06-27 01:21:21 +00:00
31 lines
823 B
TypeScript
31 lines
823 B
TypeScript
import { useCallback, useRef } from 'react';
|
|
import { getBaseApiReact } from '../App';
|
|
|
|
export const useHandleUserInfo = () => {
|
|
const userInfoRef = useRef({});
|
|
|
|
const getIndividualUserInfo = useCallback(async (address) => {
|
|
try {
|
|
if (!address) return null;
|
|
if (userInfoRef.current[address] !== undefined)
|
|
return userInfoRef.current[address];
|
|
|
|
const url = `${getBaseApiReact()}/addresses/${address}`;
|
|
const response = await fetch(url);
|
|
if (!response.ok) {
|
|
throw new Error('network error');
|
|
}
|
|
const data = await response.json();
|
|
userInfoRef.current = {
|
|
...userInfoRef.current,
|
|
[address]: data?.level,
|
|
};
|
|
return data?.level;
|
|
} catch (error) {
|
|
console.log(error);
|
|
}
|
|
}, []);
|
|
|
|
return getIndividualUserInfo;
|
|
};
|