Fetch ENS Records From A Domain – use-ens

use-ens is a React hook used to fetch ENS records from a domain.

How to use it:

1. Install and import the use-ens hook.

# NPM
$ npm i use-ens
import React, { useEffect } from 'react'
import { useWeb3React } from '@web3-react/core'
import { useENS } from 'use-ens'

2. An example app.

const App = () => {
  const { provider, activate } = useWeb3React()
  useEffect(() => {
      injected.isAuthorized().then((isAuth) => {
        if (isAuth) activate(injected)
      })
    }, [])
  const { address, records } = useENS(provider, 'dame.eth')
  return (
    <>
      <p>Address: {address ? address : ''}</p>
      <p>ENS Records</p>
      <ul>
        {records.web && Object.entries(records.web).map(([k, v]) => (
          <li>
            {k}: {v}
          </li>
        ))}
      </ul>
      {!active && <button onClick={() => activate(injected)}>Connect<button>}
    </>
  )
}

Preview:

Fetch ENS Records From A Domain - use-ens

Download Details:

Author: talentlessguy

Live Demo: View The Demo

Download Link: Download The Source Code

Official Website: https://github.com/talentlessguy/use-ens

License: MIT

You Might Be Interested In:

Tags:

Add Comment