DocsReact HooksuseFollowButton

useFollowButton

The useFollowButton hook manages the state and actions for a follow button component. It determines the current follow state between a lookupAddress and a connectedAddress, and provides functions to handle follow, unfollow, block, and mute actions.

Add to your project

import { useFollowButton } from 'ethereum-identity-kit'
 
export default function FollowButtonComponent() {
  const { buttonText, buttonState, handleAction, isLoading, disableHover, setDisableHover } = useFollowButton({
    lookupAddress: '0x1234...abcd',
    connectedAddress: '0xabcd...1234',
  })
 
  // Create your own loading states
  if (isLoading) return <div>Loading...</div>
 
  return (
    <button
      className={`follow-button ${disableHover ? 'no-hover' : ''}`}
      onClick={handleAction}
      onMouseEnter={() => setDisableHover(false)}
    >
      {buttonText}
    </button>
  )
}

Parameters

ParameterDescriptionRequiredDefault Value
lookupAddressEthereum address to manage the follow state for.Yes-
connectedAddressEthereum address of the currently connected user.No-
selectedListList number to manage the follow state for; defaults to the primary list.No-

Return Values

Return ValueDescription
buttonTextThe text to display on the follow button, indicating the current or pending follow state.
buttonStateThe current state of the button, such as ‘Follow’, ‘Following’, ‘Blocked’, etc.
handleActionFunction to handle the button click action, updating the follow state accordingly.
isLoadingBoolean indicating if the follow state is currently loading.
pendingStateThe pending state of the follow action, if any (e.g., ‘Pending Following’, ‘Pending Block’).
disableHoverBoolean indicating if hover effects should be disabled. (it is disabled after a click)
setDisableHoverFunction to set the disableHover state.

Notes

  • Ensure that the lookupAddress and connectedAddress are valid Ethereum addresses.
  • The handleAction function manages the follow, unfollow, block, and mute actions based on the current state.
  • The disableHover state can be used to control hover effects on the button during certain actions as the state is set to true every time the button is clicked.