Skip to main content

useEntityVotes

Overview

The useEntityVotes hook provides functionality to manage voting on an entity, including upvoting, downvoting, and removing votes. This hook is designed to handle optimistic updates to the entity’s state, ensuring a smooth user experience by immediately reflecting changes in the UI while making server requests in the background. It also supports callbacks for handling cases where a user is not logged in or does not have a username.

Usage Example

Parameters & Returns

Parameters

The hook accepts an object with the following fields:
Entity | undefined
required
The current entity object.
React.Dispatch<React.SetStateAction<Entity | undefined>>
required
Function to update the entity state in your component.

Returns

The hook returns an object containing the following functions:
function
Adds an upvote to the entity and updates the server.
function
Removes the user’s upvote from the entity and updates the server.
function
Adds a downvote to the entity and updates the server.
function
Removes the user’s downvote from the entity and updates the server.