Skip to main content
Returns the full achievement engine instance, providing access to all imperative methods like unlock(), setProgress(), reset(), etc.

Signature

function useAchievements<TId extends string>(): AchievementEngine<TId>

Returns

engine
AchievementEngine<TId>
The achievement engine instance with all imperative methods.

Example

import { useEffect } from "react";
import { useAchievements } from "./achievements";

function SessionInit() {
  const { unlock, isUnlocked } = useAchievements();

  useEffect(() => {
    // Check if this is a returning user
    const isReturning = isUnlocked("first-visit");

    unlock("first-visit");

    if (isReturning) {
      unlock("returning");
    }

    // Check time of day
    if (new Date().getHours() < 5) {
      unlock("night-owl");
    }
  }, [unlock, isUnlocked]);

  return null;
}
import { useAchievements } from "./achievements";

function ClickButton() {
  const { incrementProgress } = useAchievements();

  return (
    <button onClick={() => incrementProgress("click-frenzy")}>
      Click me!
    </button>
  );
}
import { useAchievements } from "./achievements";

function ResetButton() {
  const { reset } = useAchievements();

  return (
    <button onClick={reset}>
      Reset All Achievements
    </button>
  );
}

Notes

  • This hook does not cause re-renders when state changes - use reactive hooks like useIsUnlocked or useProgress for reactive UI
  • Must be used within an AchievementsProvider or the factory’s Provider
  • Use this hook when you need to imperatively trigger achievement actions (unlock, progress updates, etc.)
  • For reading reactive state, prefer specialized hooks like useIsUnlocked, useProgress, or useUnlockedCount

Build docs developers (and LLMs) love