platformer - v1.0.0
    Preparing search index...

    Function useLeaderboard

    • React hook for managing a persistent leaderboard stored in localStorage.

      Scores are stored under the leaderboard key and sorted in descending order. If a player already exists, their score is only updated if the new score is higher.

      Returns {
          clear: () => void;
          leaderboard: LeaderboardEntry[];
          saveScore: (name: string, score: number) => void;
      }

      An object containing:

      • leaderboard: Sorted leaderboard entries.
      • saveScore: Function to add or update a player's score.
      • clear: Function to reset the leaderboard.
      • clear: () => void

        Clears all leaderboard entries.

      • leaderboard: LeaderboardEntry[]
      • saveScore: (name: string, score: number) => void

        Saves or updates a player's score.

        If the player already exists, their score will only be updated if the new score is higher than the existing one.

      const { leaderboard, saveScore, clear } = useLeaderboard();
      saveScore('Alice', 100);