mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-05-14 05:37:52 +00:00
35 lines
800 B
TypeScript
35 lines
800 B
TypeScript
import React, { 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) {
|
|
//error
|
|
}
|
|
}, [])
|
|
|
|
return {
|
|
getIndividualUserInfo,
|
|
};
|
|
};
|