@lyncworld/fuel-marketplace
Version:
Marketplace NPM SDK on Fuel blockchain. Powered by LYNC, it allows anyone to create their own decentralized marketplace which includes listing and buying of Non-fungible tokens (NFTs) and Semi-fungible tokens (SFTs) in a few lines of code.
41 lines (34 loc) • 1.14 kB
text/typescript
import { useCallback, useEffect, useState } from 'react';
import { HooksReturn, MarketplaceCollections, HooksArgs } from '@/interfaces';
import { getCollections } from '@/ssr';
export const useCollections = ({ network, limit }: HooksArgs): Readonly<HooksReturn<MarketplaceCollections[]>> => {
const [fetching, setFetching] = useState<boolean>(true);
const [data, setData] = useState<MarketplaceCollections[]>([]);
const [error, setError] = useState<unknown>(null);
const fetchData = useCallback(async () => {
setFetching(true);
setError(null);
try {
const collections = await getCollections({
network,
limit,
});
if (collections.success) {
setError(null);
setData(collections.data);
} else {
setError(collections.error);
setData([]);
}
} catch (error: unknown) {
setError(error);
setData([]);
} finally {
setFetching(false);
}
}, [network, limit]);
useEffect(() => {
fetchData();
}, [fetchData]);
return { fetching, data, error } as const satisfies HooksReturn<MarketplaceCollections[]>;
};