Skip to Content

🚧 These packages are still in development and may change rapidly as they are developed.

ReactuseNameFromAddress

useNameFromAddress

Hook for fetching the name associated with an Aptos account address.

Usage

import { useNameFromAddress } from "@aptos-labs/react"; export default function App() { const { data: name, isLoading } = useNameFromAddress({ address: "0x926ff619e85bdb5b02680f27bea5ea3302c71f86be4b16fa0d63df213add927a", }); if (isLoading) { return <div>Loading name...</div>; } return <div>Name: {name?.toString() ?? "No name found"}</div>; }

Parameters

NameTypeDefault
addressAccountAddressInput

The address to fetch the ANS name for.

networkNetworkInfo

The network to use for the request. If not set, the network of the AptosJSProClient instance will be used.

subscribedboolean

Set this to false to unsubscribe this observer from updates to the query cache. Defaults to true.

enabledEnabled<FetchNameFromAddressResult, Error, FetchNameFromAddressResult, readonly unknown[]>

Set this to false or a function that returns false to disable automatic refetching when the query mounts or changes query keys. To refetch the query, use the refetch method returned from the useQuery instance. Accepts a boolean or function that returns a boolean. Defaults to true.

staleTimeStaleTimeFunction<FetchNameFromAddressResult, Error, FetchNameFromAddressResult, readonly unknown[]>

The time in milliseconds after data is considered stale. If set to Infinity, the data will never be considered stale. If set to a function, the function will be executed with the query to compute a staleTime. Defaults to 0.

refetchIntervalnumber | false | ((query: Query<FetchNameFromAddressResult, Error, FetchNameFromAddressResult, readonly unknown[]>) => number | ... 1 more ... | undefined)

If set to a number, the query will continuously refetch at this frequency in milliseconds. If set to a function, the function will be executed with the latest data and query to compute a frequency Defaults to false.

refetchIntervalInBackgroundboolean

If set to true, the query will continue to refetch while their tab/window is in the background. Defaults to false.

refetchOnWindowFocusboolean | "always" | ((query: Query<FetchNameFromAddressResult, Error, FetchNameFromAddressResult, readonly unknown[]>) => boolean | "always")

If set to true, the query will refetch on window focus if the data is stale. If set to false, the query will not refetch on window focus. If set to 'always', the query will always refetch on window focus. If set to a function, the function will be executed with the latest data and query to compute the value. Defaults to true.

refetchOnReconnectboolean | "always" | ((query: Query<FetchNameFromAddressResult, Error, FetchNameFromAddressResult, readonly unknown[]>) => boolean | "always")

If set to true, the query will refetch on reconnect if the data is stale. If set to false, the query will not refetch on reconnect. If set to 'always', the query will always refetch on reconnect. If set to a function, the function will be executed with the latest data and query to compute the value. Defaults to the value of networkOnline (true)

refetchOnMountboolean | "always" | ((query: Query<FetchNameFromAddressResult, Error, FetchNameFromAddressResult, readonly unknown[]>) => boolean | "always")

If set to true, the query will refetch on mount if the data is stale. If set to false, will disable additional instances of a query to trigger background refetch. If set to 'always', the query will always refetch on mount. If set to a function, the function will be executed with the latest data and query to compute the value Defaults to true.

retryOnMountboolean

If set to false, the query will not be retried on mount if it contains an error. Defaults to true.

notifyOnChangePropsNotifyOnChangeProps

If set, the component will only re-render if any of the listed properties change. When set to ['data', 'error'], the component will only re-render when the data or error properties change. When set to 'all', the component will re-render whenever a query is updated. When set to a function, the function will be executed to compute the list of properties. By default, access to properties will be tracked, and the component will only re-render when one of the tracked properties change.

throwOnErrorThrowOnError<FetchNameFromAddressResult, Error, FetchNameFromAddressResult, readonly unknown[]>

Whether errors should be thrown instead of setting the error property. If set to true or suspense is true, all errors will be thrown to the error boundary. If set to false and suspense is false, errors are returned as state. If set to a function, it will be passed the error and the query, and it should return a boolean indicating whether to show the error in an error boundary (true) or return the error as state (false). Defaults to false.

select(data: FetchNameFromAddressResult) => FetchNameFromAddressResult

This option can be used to transform or select a part of the data returned by the query function.

placeholderDataFetchNameFromAddressResult | PlaceholderDataFunction<FetchNameFromAddressResult, Error, FetchNameFromAddressResult, readonly unknown[]>

If set, this value will be used as the placeholder data for this particular query observer while the query is still in the loading data and no initialData has been provided.

_optimisticResults"optimistic" | "isRestoring"
experimental_prefetchInRenderboolean

Enable prefetching during rendering

retryRetryValue<Error>

If false, failed queries will not retry by default. If true, failed queries will retry infinitely., failureCount: num If set to an integer number, e.g. 3, failed queries will retry until the failed query count meets that number. If set to a function (failureCount, error) => boolean failed queries will retry until the function returns false.

retryDelayRetryDelayValue<Error>
networkModeNetworkMode
gcTimenumber

The time in milliseconds that unused/inactive cache data remains in memory. When a query’s cache becomes unused or inactive, that cache data will be garbage collected after this duration. When different garbage collection times are specified, the longest one will be used. Setting it to Infinity will disable garbage collection.

persister(queryFn: QueryFunction<FetchNameFromAddressResult, readonly unknown[], never>, context: { client: QueryClient; queryKey: readonly unknown[]; signal: AbortSignal; meta: Record<...> | undefined; pageParam?: unknown; direction?: unknown; }, query: Query<...>) => FetchNameFromAddressResult | Promise<...>
queryHashstring
queryKeyHashFnQueryKeyHashFunction<readonly unknown[]>
initialDataFetchNameFromAddressResult | InitialDataFunction<FetchNameFromAddressResult>
initialDataUpdatedAtnumber | (() => number | undefined)
behaviorQueryBehavior<FetchNameFromAddressResult, Error, FetchNameFromAddressResult, readonly unknown[]>
structuralSharingboolean | ((oldData: unknown, newData: unknown) => unknown)

Set this to false to disable structural sharing between query results. Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom structural sharing logic. Defaults to true.

_defaultedboolean
metaRecord<string, unknown>

Additional payload to be stored on each query. Use this property to pass information that can be used in other places.

maxPagesnumber

Maximum number of pages to store in the data of an infinite query.

Return Type

NameTypeDefault
dataFetchNameFromAddressResult | undefined

The last successfully resolved data for the query. The last successfully resolved data for the query. The last successfully resolved data for the query. The last successfully resolved data for the query. The last successfully resolved data for the query. The last successfully resolved data for the query.

errorError | null

The error object for the query, if an error was thrown.

  • Defaults to null. The error object for the query, if an error was thrown.
  • Defaults to null. The error object for the query, if an error was thrown.
  • Defaults to null. The error object for the query, if an error was thrown.
  • Defaults to null. The error object for the query, if an error was thrown.
  • Defaults to null. The error object for the query, if an error was thrown.
  • Defaults to null.
isErrorboolean

A derived boolean from the status variable, provided for convenience.

  • true if the query attempt resulted in an error. A derived boolean from the status variable, provided for convenience.
  • true if the query attempt resulted in an error. A derived boolean from the status variable, provided for convenience.
  • true if the query attempt resulted in an error. A derived boolean from the status variable, provided for convenience.
  • true if the query attempt resulted in an error. A derived boolean from the status variable, provided for convenience.
  • true if the query attempt resulted in an error. A derived boolean from the status variable, provided for convenience.
  • true if the query attempt resulted in an error.
isPendingboolean

Will be pending if there’s no cached data and no query attempt was finished yet. Will be pending if there’s no cached data and no query attempt was finished yet. Will be pending if there’s no cached data and no query attempt was finished yet. Will be pending if there’s no cached data and no query attempt was finished yet. Will be pending if there’s no cached data and no query attempt was finished yet. Will be pending if there’s no cached data and no query attempt was finished yet.

isLoadingboolean

Is true whenever the first fetch for a query is in-flight.

  • Is the same as isFetching && isPending.
isLoadingErrorboolean

Will be true if the query failed while fetching for the first time. Will be true if the query failed while fetching for the first time. Will be true if the query failed while fetching for the first time. Will be true if the query failed while fetching for the first time. Will be true if the query failed while fetching for the first time. Will be true if the query failed while fetching for the first time.

isRefetchErrorboolean

Will be true if the query failed while refetching. Will be true if the query failed while refetching. Will be true if the query failed while refetching. Will be true if the query failed while refetching. Will be true if the query failed while refetching. Will be true if the query failed while refetching.

isSuccessboolean

A derived boolean from the status variable, provided for convenience.

  • true if the query has received a response with no errors and is ready to display its data. A derived boolean from the status variable, provided for convenience.
  • true if the query has received a response with no errors and is ready to display its data. A derived boolean from the status variable, provided for convenience.
  • true if the query has received a response with no errors and is ready to display its data. A derived boolean from the status variable, provided for convenience.
  • true if the query has received a response with no errors and is ready to display its data. A derived boolean from the status variable, provided for convenience.
  • true if the query has received a response with no errors and is ready to display its data. A derived boolean from the status variable, provided for convenience.
  • true if the query has received a response with no errors and is ready to display its data.
isPlaceholderDataboolean

Will be true if the data shown is the placeholder data. Will be true if the data shown is the placeholder data. Will be true if the data shown is the placeholder data. Will be true if the data shown is the placeholder data. Will be true if the data shown is the placeholder data. Will be true if the data shown is the placeholder data.

status"error" | "success" | "pending"

The status of the query.

  • Will be:
    • pending if there’s no cached data and no query attempt was finished yet.
    • error if the query attempt resulted in an error.
    • success if the query has received a response with no errors and is ready to display its data. The status of the query.
  • Will be:
    • pending if there’s no cached data and no query attempt was finished yet.
    • error if the query attempt resulted in an error.
    • success if the query has received a response with no errors and is ready to display its data. The status of the query.
  • Will be:
    • pending if there’s no cached data and no query attempt was finished yet.
    • error if the query attempt resulted in an error.
    • success if the query has received a response with no errors and is ready to display its data. The status of the query.
  • Will be:
    • pending if there’s no cached data and no query attempt was finished yet.
    • error if the query attempt resulted in an error.
    • success if the query has received a response with no errors and is ready to display its data. The status of the query.
  • Will be:
    • pending if there’s no cached data and no query attempt was finished yet.
    • error if the query attempt resulted in an error.
    • success if the query has received a response with no errors and is ready to display its data. The status of the query.
  • Will be:
    • pending if there’s no cached data and no query attempt was finished yet.
    • error if the query attempt resulted in an error.
    • success if the query has received a response with no errors and is ready to display its data.
dataUpdatedAtnumber

The timestamp for when the query most recently returned the status as "success".

errorUpdatedAtnumber

The timestamp for when the query most recently returned the status as "error".

failureCountnumber

The failure count for the query.

  • Incremented every time the query fails.
  • Reset to 0 when the query succeeds.
failureReasonError | null

The failure reason for the query retry.

  • Reset to null when the query succeeds.
errorUpdateCountnumber

The sum of all errors.

isFetchedboolean

Will be true if the query has been fetched.

isFetchedAfterMountboolean

Will be true if the query has been fetched after the component mounted.

  • This property can be used to not show any previously cached data.
isFetchingboolean

A derived boolean from the fetchStatus variable, provided for convenience.

  • true whenever the queryFn is executing, which includes initial pending as well as background refetch.
isInitialLoadingboolean
isPausedboolean

A derived boolean from the fetchStatus variable, provided for convenience.

  • The query wanted to fetch, but has been paused.
isRefetchingboolean

Is true whenever a background refetch is in-flight, which does not include initial pending.

  • Is the same as isFetching && !isPending.
isStaleboolean

Will be true if the data in the cache is invalidated or if the data is older than the given staleTime.

refetch(options?: RefetchOptions | undefined) => Promise<QueryObserverResult<FetchNameFromAddressResult, Error>>

A function to manually refetch the query.

fetchStatusFetchStatus

The fetch status of the query.

  • fetching: Is true whenever the queryFn is executing, which includes initial pending as well as background refetch.
  • paused: The query wanted to fetch, but has been paused.
  • idle: The query is not fetching.
  • See Network Mode  for more information.
promisePromise<FetchNameFromAddressResult>

A stable promise that will be resolved with the data of the query. Requires the experimental_prefetchInRender feature flag to be enabled.

Last updated on