refactor useProfile and useChannelProfile hooks
This commit is contained in:
14
src/utils/hooks/useProfile.tsx
Normal file
14
src/utils/hooks/useProfile.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import useSWR from 'swr';
|
||||
|
||||
const fetcher = (url: string) => fetch(url).then((r: any) => r.json());
|
||||
|
||||
export const useProfile = (pubkey: string) => {
|
||||
const { data, error } = useSWR(`https://rbr.bio/${pubkey}/metadata.json`, fetcher);
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
if (data) {
|
||||
return JSON.parse(data.content);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Reference in New Issue
Block a user