useFollow

useFollow is a React Hook that lets you follow a profile.

const { data, loading } = useFollow();

Usage

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

type ProfileFollowProps = {
  profile: ProfileFragment;
};

export function FollowProfile({ profile }: ProfileFollowProps) {
  const { follow, isPending } = useFollow({ profile });

  if (profile.isFollowedByMe || profile.isOptimisticFollowedByMe) {
    return <p>Following</p>;
  }

  return (
    <button onClick={follow} disabled={isPending}>
      {isPending ? 'Follow in progress...' : 'Follow'}
    </button>
  );
}

Reference

useFollow()

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

type ProfileFollowProps = {
  profile: ProfileFragment;
};

function FollowProfile({ profile }: ProfileFollowProps) {
  const { follow, isPending } = useFollow({ profile });
  // ...
}

Parameters

  • profile: ProfileFragment: the profile you wish to follow

Returns

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

follow function

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

follow()

Parameters

  • follow takes no parameters (the profile is supplied to useFollow directly)