Skip to main content

Overview

Combines follow status fetching and toggle actions into a single hook. On mount, loads whether the current user follows userId, then provides a toggleFollow function to follow or unfollow in one call. For integration guidance, see Relationships — useFollowManager.

Usage Example

import { useFollowManager } from "@replyke/react-js";

function FollowButton({ userId }: { userId: string }) {
  const { isFollowing, isLoading, toggleFollow } = useFollowManager({ userId });

  return (
    <button onClick={toggleFollow} disabled={isLoading || isFollowing === null}>
      {isFollowing ? "Unfollow" : "Follow"}
    </button>
  );
}

Parameters

userId
string
required
The ID of the target user.

Returns

isFollowing
boolean | null
true if following, false if not, null while the initial status is loading.
isLoading
boolean
true while the initial status check is in progress.
toggleFollow
() => Promise<void>
Follows the user if not currently following; unfollows if currently following. No-ops while loading or if userId is the current user’s own ID.