Animated

Animated: React

Start the cursor in an effect and clean up on unmount.

npm install glint-cursors

Install it as a regular dependency: it ships runtime code.

The effect-hook pattern

Mount this once, near the root of your app:

import { useEffect } from 'react';
import { loadCursor } from 'glint-cursors/animated';

// Serialize loads so a cancelled effect cannot destroy a newer instance.
let pending = Promise.resolve();

export function Cursor({ family = 'morph', variant = 'light', scope }) {
  useEffect(() => {
    let cursor = null;
    let cancelled = false;
    pending = pending.then(async () => {
      if (cancelled) return;
      const c = await loadCursor({ family, variant, scope });
      if (cancelled) c?.destroy();
      else cursor = c;
    }).catch((error) => console.error('Cursor could not load:', error));
    return () => {
      cancelled = true;
      cursor?.destroy();
    };
  }, [family, variant, scope]);
  return null;
}
  • loadCursor resolves to null when the primary pointer or accessibility settings block it. Invalid options and failed imports can reject the promise; handle errors in your app.
  • The runtime uses a shared active instance. Mount one cursor component at a time; the queue above serializes effect replay and option changes within this module. Coordinate ownership if other code also loads a cursor.
  • The cursor never causes React re-renders; it doesn’t touch state on pointer moves.

The example uses a plain hook rather than a React wrapper.

Labels and arrows

<a href="/work/1" data-cursor-label="View">…</a>
<button data-cursor-direction="right" onClick={next}>Next</button>

Make sure what the label says is also visible on the page. See Attributes.

Theme changes

Keep the handle and call cursor.setColors('dark') when your site switches theme, instead of recreating it.