useCampaign
Hook for fetching a single valid campaign that has been created on Metrom.
Import
import { useCampaign } from "@metrom-xyz/react";
Usage
import { useCampaign } from "@metrom-xyz/react";
function App() {
const { isLoading, data } = useCampaign({
chainId: 1,
id: "0xa8b1dc25d4ea47406771c4db401455a5d8b377dff381e2aea2722084808b4b47",
});
if (isLoading) return <div>loading...</div>;
if (!data) return <div>campaign not found</div>;
return (
<div>
<p>{data.chainId}</p>
<p>{data.from}</p>
<p>{data.to}</p>
</div>
);
}
Parameters
import { type useCampaignParams } from "@metrom-xyz/react";
chainId
number | undefined
Chain id of the campaign; the chain id is where the campaign lives in. Defaults
to undefiend
.
import { useCampaign } from "@metrom-xyz/react";
function App() {
const { isLoading, data } = useCampaign({
chainId: 1,
});
}
id
Hex | undefined
Id of the campaign.Defaults to undefiend
.
import { useCampaign } from "@metrom-xyz/react";
function App() {
const { isLoading, data } = useCampaign({
id: "0xa8b1dc25d4ea47406771c4db401455a5d8b377dff381e2aea2722084808b4b47",
});
}
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 useCampaignReturnValue } from "@metrom-xyz/react";
data
Campaign | undefined
Fetched campaign. 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.