Guides

useUnfollow

useUnfollow is a React Hook that lets you unfollow a profile.

const { execute, error, isPending } = useUnfollow();

Usage

import { ProfileFragment, useUnfollow } from '@lens-protocol/react-web';

type ProfileUnfollowProps = {
  profile: ProfileFragment;
};

export function UnfollowProfile({ profile }: ProfileUnfollowProps) {
  const { execute: unfollow, isPending } = useUnfollow({ profile });

  if (!profile.isFollowedByMe) {
    return null;
  }

  return (
    <button onClick={unfollow} disabled={isPending}>
      {isPending ? 'Unfollowing...' : 'Unfollow'}
    </button>
  );
}

Reference

useUnfollow()

Call useUnfollow where your unfollow button markup is and provide the profile that you would like to unfollow.

type ProfileUnfollowProps = {
  profile: ProfileFragment;
};

export function UnfollowProfile({ profile }: ProfileUnfollowProps) {
  const { unfollow, isPending } = useUnfollow({ profile });
  // ...
}

Parameters

  • profile: ProfileFragment: the profile you wish to unfollow

Returns

  • unfollow an async function that returns void used to unfollow a profile on button click
  • isPending a boolean flag that informs you if an unfollow is in progress

execute function

The execute function returned by useUnfollow allows you to programmatically unfollow a profile, usually in a on click handler of a button. It takes no parameters.

Parameters

execute takes no parameters (the profile is supplied to useUnfollow directly)