useLnrGetAddress
The useLnrGetAddress react hook allows you to get the address associated with a name.
Usage
To use the useLnrGetAddress hook, you need to import it and call it in your functional component. The hook takes a name parameter, which is the name you want to resolve to an address.
MyComponent.tsx
import { useLnrGetAddress } from '@linagee/lnr-ethers-react';
function MyComponent() {
const { address } = useLnrGetAddress('0xhal.og');
// ...
}
You can also use object destructuring to get individual properties from the returned object:
MyComponent.tsx
import { useLnrGetAddress } from '@linagee/lnr-ethers-react';
function MyComponent() {
const { address, error, hasError, loading } = useLnrGetAddress('0xhal.og');
// ...
}
Parameters
- name (string): The name to get the address of.
Returns
The hook returns an object with the following properties:
- address (string | null): The address associated with the name, or null if no address is found
- error (string | null): The error message if an error occurs, or null if no error occurs
- hasError (boolean): Indicates whether an error has occurred.
- loading (boolean): Indicates whether the data is currently loading.
Example
Here is an example of how you can use the useLnrGetAddress hook in a functional component:
MyComponent.tsx
import React from "react";
import { useLnrGetAddress } from "@linagee/lnr-ethers-react";
function MyComponent() {
const name = "0xhal.og";
const { address, error, hasError, loading } = useLnrGetAddress(name);
if (loading) {
return <div>Loading...</div>;
}
if (hasError) {
return <div>Error: {error}</div>;
}
return (
<div>
<h2>Name: {name}</h2>
<p>Address: {address}</p>
</div>
);
}
export default MyComponent;