DocsReact HooksuseUserInfo

useUserInfo

The useUserInfo hook provides comprehensive functionality for fetching and managing a user’s followers and following data, including advanced features like tag filtering, search, sorting, and infinite pagination.

Add to your project

import { useUserInfo } from 'ethereum-identity-kit'
 
export default function UserProfile() {
  const {
    followers,
    following,
    followerTags,
    followingTags,
    followersIsLoading,
    followingIsLoading,
    fetchMoreFollowers,
    fetchMoreFollowing,
    followingSearch,
    setFollowingSearch,
    followingSort,
    setFollowingSort,
    toggleTag,
  } = useUserInfo('vitalik.eth')
 
  // --- Your component code here ---
}

Parameters

ParameterDescriptionRequiredType
userEthereum Address, ENS name, or list number to fetch followers/following data for.Yesstring

The hook automatically detects whether the input is an address, ENS name, or list number and handles the API calls accordingly.

Return Values

Core Data

Return ValueDescriptionType
followersArray of follower profiles with address and tag information.FollowerResponse[]
followingArray of following profiles with address and tag information.FollowingResponse[]
followerTagsTag data for followers including counts and categories.TagsResponse
followingTagsTag data for following including counts and categories.TagsResponse
listNumList number if the user input was a valid list.number | undefined
userIsListBoolean indicating if the user input represents a list number.boolean

Loading States

Return ValueDescriptionType
followersIsLoadingLoading state for followers data (includes refetching).boolean
followingIsLoadingLoading state for following data (includes refetching).boolean
followerTagsLoadingLoading state for follower tags data.boolean
followingTagsLoadingLoading state for following tags data.boolean

Pagination

Return ValueDescriptionType
fetchMoreFollowersFunction to fetch next page of followers.() => Promise<InfiniteQueryObserverResult>
fetchMoreFollowingFunction to fetch next page of following.() => Promise<InfiniteQueryObserverResult>
isEndOfFollowersBoolean indicating if all followers have been loaded.boolean
isEndOfFollowingBoolean indicating if all following have been loaded.boolean
isFetchingMoreFollowersBoolean indicating if currently fetching more followers.boolean
isFetchingMoreFollowingBoolean indicating if currently fetching more following.boolean

Search & Filtering

Return ValueDescriptionType
followersSearchCurrent search query for followers.string
followingSearchCurrent search query for following.string
setFollowersSearchFunction to update followers search query.(search: string) => void
setFollowingSearchFunction to update following search query.(search: string) => void
followersTagsFilterArray of selected tag filters for followers.string[]
followingTagsFilterArray of selected tag filters for following.string[]
setFollowersTagsFilterFunction to set follower tag filters.(tags: string[]) => void
setFollowingTagsFilterFunction to set following tag filters.(tags: string[]) => void
toggleTagFunction to toggle a specific tag filter for followers/following.(tab: ProfileTabType, tag: string) => void

Sorting

Return ValueDescriptionType
followersSortCurrent sort option for followers.FollowSortType
followingSortCurrent sort option for following.FollowSortType
setFollowersSortFunction to update followers sort option.(sort: FollowSortType) => void
setFollowingSortFunction to update following sort option.(sort: FollowSortType) => void

Features

Automatic Data Validation

The hook automatically validates the input and determines whether it’s an Ethereum address, ENS name, or list number.

Infinite Pagination

Built-in infinite scrolling support with pagination management and end-of-data detection.

Advanced Filtering

  • Search: Filter by profile name or address
  • Tags: Filter by custom tags with multi-select support
  • Sorting: Multiple sort options including follower count, alphabetical, and more

Performance Optimization

  • Stale Time: 30-second cache for reduced API calls
  • Conditional Fetching: Only fetches when valid user data is provided
  • Refetch Control: Disabled window focus refetching for better UX

Tag Management

Comprehensive tag system with counting, filtering, and toggle functionality for both followers and following lists.

⚠️

The hook expects a valid Ethereum address, ENS name, or list number. Invalid inputs will result in empty data arrays but won’t cause errors.

This hook uses React Query for data fetching and caching. It provides automatic background updates and error handling while maintaining a responsive user experience.

Example Usage

import { useUserInfo } from 'ethereum-identity-kit'
 
function UserFollowersPage({ userAddress }) {
  const {
    followers,
    following,
    followersIsLoading,
    fetchMoreFollowers,
    isEndOfFollowers,
    followingSearch,
    setFollowingSearch,
    followingSort,
    setFollowingSort,
    toggleTag,
  } = useUserInfo(userAddress)
 
  return (
    <div>
      <input
        value={followingSearch}
        onChange={(e) => setFollowingSearch(e.target.value)}
        placeholder="Search following..."
      />
 
      <select value={followingSort} onChange={(e) => setFollowingSort(e.target.value)}>
        <option value="follower count">By Followers</option>
        <option value="alphabetical">Alphabetical</option>
      </select>
 
      {followersIsLoading ? (
        <div>Loading...</div>
      ) : (
        <div>
          {followers.map((follower) => (
            <div key={follower.address}>{/* Render follower */}</div>
          ))}
 
          {!isEndOfFollowers && <button onClick={() => fetchMoreFollowers()}>Load More</button>}
        </div>
      )}
    </div>
  )
}