React & React NativeHooksRelationshipsuseFollowUser

useFollowUser

Overview

The useFollowUser hook allows a logged-in user to follow another user within the current project. This hook ensures that users can only follow valid targets and handles necessary validations.

Usage Example

import { useFollowUser } from "@replyke/react-js";
 
function FollowUserButton({ targetUserId }: { targetUserId: string }) {
  const followUser = useFollowUser();
 
  const handleFollowUser = async () => {
    try {
      await followUser({ userId: targetUserId });
      console.log("Successfully followed the user.");
    } catch (error) {
      console.error("Failed to follow user:", error.message);
    }
  };
 
  return <button onClick={handleFollowUser}>Follow User</button>;
}

Parameters & Returns

Parameters

The hook returns a function that accepts an object with the following field:

ParameterTypeRequiredDescription
userIdstringYesThe ID of the user to follow.

Returns

The function does not return a value but ensures the follow action is executed successfully on the server.