Laravel Packages

Beam: Feature Flags for the Frontend with Laravel Pennant

Published
Beam: Feature Flags for the Frontend with Laravel Pennant image

Beam is a feature flags library for the frontend, powered by Laravel Pennant. It features a lightweight footprint, with a simple, promise-based API and great TypeScript types. It also features first-class React hooks and Vue composables.

// Fetch a single flag
import { useFeatureFlag } from '@beacon-hq/beam/react';

export function FeatureGate() {
    const { status, loading, refresh } = useFeatureFlag('new-ui');

    if (loading) return <span>Loading…</span>;
    return (
        <div>
            {status ? 'Feature On' : 'Feature Off'}
            <button onClick={() => refresh()}>Refresh</button>
        </div>
    );
}

/*
`useFeatureFlag` returns:
{ 
    featureFlag: string; 
    status: boolean; 
    value?: any, 
    loading: boolean, 
    refresh: fn () => void 
}
*/

Beam also supports scope and extra dependencies that trigger a refetch when changed:

import { useFeatureFlag } from '@beacon-hq/beam/react';

function Profile({ userId }: { userId: number }) {
  const scope = { userId };
  const feature = useFeatureFlag('beta-ui', { deps: [userId] }, scope);
  return feature.status ? <NewUI /> : <LegacyUI />;
}

You can get started with this library by reading the Beam documentation. The source code is available on GitHub at beacon-hq/beam. The frontend library works in tandem with the beacon-hq/pennant-beam Composer dependency.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
Slow Job Alerts and Replica Commit IDs in Laravel 13.40 image

Slow Job Alerts and Replica Commit IDs in Laravel 13.40

Read article
Flock: A Free, Native Herd Alternative for Laravel image

Flock: A Free, Native Herd Alternative for Laravel

Read article
Live Props for Real-Time Updates in Inertia.js v3.11 image

Live Props for Real-Time Updates in Inertia.js v3.11

Read article
Cooldown Dependency Policy now in Composer 2.11 image

Cooldown Dependency Policy now in Composer 2.11

Read article
Email Sending and Testing for Laravel in One Account image

Email Sending and Testing for Laravel in One Account

Read article
Decide with Jev: Tie Every AI Check to the Exact Draft image

Decide with Jev: Tie Every AI Check to the Exact Draft

Read article