Glim Guides · Tutorial

How to embed Glim in React and Next.js

Step-by-step tutorial: install @axaylabs/glim, mount a companion in React/Next.js, sync AI request states, and clean up on unmount.

2026-07-22 7 min read For AI product builders

Glim is a browser-first library with a tiny API. In React and Next.js you mount it inside a layout effect, drive states from your data layer, and destroy on unmount.

Install

npm i @axaylabs/glim

Or load https://getglim.dev/glim.js and use window.Glim.

React client component

'use client';
import { useEffect, useRef } from 'react';
import { Glim } from '@axaylabs/glim';

export function Companion({ state = 'idle' }) {
  const ref = useRef(null);
  const pRef = useRef(null);

  useEffect(() => {
    pRef.current = Glim.mount(ref.current, 'wisp', { size: 140 });
    return () => pRef.current?.destroy();
  }, []);

  useEffect(() => {
    pRef.current?.setState(state);
  }, [state]);

  return <div ref={ref} aria-hidden="true" />;
}

Next.js notes

Wire to a fetch / stream

setMind('thinking');
const res = await fetch('/api/chat', { method: 'POST', body });
setMind('talking');
// ... read stream ...
setMind('idle');

Try the offline path

Download the starter from getglim.dev if you want a zero-bundler proof before touching React.

Try Glim free. Offline starter + MIT creatures. No fake checkout.