claps icon indicating copy to clipboard operation
claps copied to clipboard

Refactor Claps Component to Use Custom Hooks for Improved Modularity

Open halilatilla opened this issue 10 months ago • 0 comments

Description

This PR introduces a series of refactorings to the Claps component to improve its modularity. The primary focus was encapsulating the state and interaction logic into custom hooks.

Changes

  1. Custom Hook for Data Fetching (useClapData):
    • Extracted data fetching logic into a custom hook, which is responsible for fetching clap data from the server and managing the loading state. This abstraction simplifies the main component structure and enhances the separation of concerns.
  2. Custom Hook for Clap Interaction (useClapSavingAndInteraction):
    • Developed a new hook that encapsulates the functionality for handling clap interactions (PATCH requests) and local state updates related to user interactions (e.g., animation state, and clap count cache).
    • This hook manages the states for reaction and cacheCount, handling the complexities of updating these states internally based on the server's response.
  3. Simplification of the Claps Component:
    • With the heavy lifting moved into hooks, the main Claps component now primarily handles rendering and uses these hooks for all logic.

halilatilla avatar Apr 12 '24 10:04 halilatilla