useCampaigns
Hook for fetching all the valid campaigns that have been created on Metrom. Supports optional filtering.
Import
import { useCampaigns } from "@metrom-xyz/react";
Usage
import { useCampaigns } from "@metrom-xyz/react";
function App() {
const { isLoading, data } = useCampaigns();
if (isLoading) return <div>loading...</div>;
if (!data) return <div>no campaigns</div>;
return (
<div>
{data.map((campaign) => (
<div key={campaign.id}>
<p>{campaign.chainId}</p>
<p>{campaign.from}</p>
<p>{campaign.to}</p>
</div>
))}
</div>
);
}
Parameters
import { type UseCampaignsParams } from "@metrom-xyz/react";
status
CampaignStatus | undefined
Optional campaign status to filter for. Defaults to undefined
.
import { useCampaigns, CampaignStatus } from "@metrom-xyz/react";
function App() {
const { isLoading, data } = useCampaigns({
status: CampaignStatus.Active,
});
}
owner
Address | undefined
Optional campaign owner to filter for; the owner can be different from the
campaign creator if the ownership was transferred. Defaults to undefined
.
import { useCampaigns } from "@metrom-xyz/react";
function App() {
const { isLoading, data } = useCampaigns({
owner: "0x0000000000000000000000000000000000000000",
});
}
chainId
number | undefined
Optional campaign chain id to filter for; the chain id is where the campaign
lives in. Defaults to undefined
.
import { useCampaigns } from "@metrom-xyz/react";
function App() {
const { isLoading, data } = useCampaigns({
chainId: 1,
});
}
dex
SupportedDex | undefined
Optional campaign targeted dex. Defaults to undefined
.
import { useCampaigns, SupportedDex } from "@metrom-xyz/react";
function App() {
const { isLoading, data } = useCampaigns({
dex: SupportedDex.UniswapV3,
});
}
options
TanStack Query parameters. See the TanStack Query query docs for more info.
Metrom React library does not support all TanStack Query parameters, like
queryFn
and queryKey
, are used internally and cannot be overriden. Check
out the
source
to see what parameters are not supported.
Return Type
import { type UseCampaignsReturnValue } from "@metrom-xyz/react";
data
Campaign[] | undefined
List of fetched campaigns. Defaults to undefiend
.
isPending
boolean
Is true whenever there’s no cached data and no query attempt was finished yet.
isLoading
boolean
Is true whenever the first fetch for a query is in-flight.
isFetching
boolean
Is true whenever the queryFn is executing, which includes initial pending as well as background refetches.