npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

laika-react

v2.0.0

Published

React Laika client

Readme

laika-react

CI codecov npm version License: MIT

This NPM package connects React applications with the Laika feature flag service (https://github.com/MEDIGO/laika)

Supports React 17 and React 18

Installation

npm:

npm install laika-react

yarn:

yarn add laika-react

Usage

React Hook

Without context:

import React from 'react'
import { useLaika } from 'laika-react'
/* ... import your components ... */

const uri = 'https://laika.example.com'
const env = 'prod'

function SomeComponent() {
  const [featureNewComponent] = useLaika('new-component', uri, env)

  return (
    <div>
      {featureNewComponent ? <NewComponent /> : <OldComponent />}
    </div>
  )
}

With context:

import React from 'react'
import { useLaika, Config, LaikaContext } from 'laika-react'
/* ... import your components ... */

const ctx: Config = {
  uri: "https://laika.example.com",
  env: "prod",
  timeout: 60 * 1000, // 1 minute cache timeout
}

function App() {
  return (
    <LaikaContext.Provider value={ctx}>
      <SomeComponent/>
    </LaikaContext.Provider>
  )
}

function SomeComponent() {

  // We can leave out the parameters that we provided in the context
  const [featureNewComponent] = useLaika('new-component')

  return (
    <div>
      {featureNewComponent ? <NewComponent /> : <OldComponent />}
    </div>
  )
}

Component

import React from 'react'
import { useLaika, Config, LaikaContext, Laika } from 'laika-react'
/* ... import your components ... */

const uri = 'https://laika.example.com'
const env = 'prod'

function SomeComponent() {
  return (
    <div>
      <Laika
        feature="component-test"
        uri={uri} // You can leave out uri and env just like with the 
                  // hook and have them be loaded from the context if you provided one
        env={env}
        onTrue={<NewComponent />}
        onFalse={<OldComponent />}
      />
    </div>
  )
}

Promise (getFeatureStatus)

import { getFeatureStatus } from 'laika-react'

getFeatureStatus('NEW_FEATURE', 'http://example.com', 'prod')
  .then(status => {
    if (status) {
      console.log('feature enabled')
    }
  })

Notes

  • It is strongly recommended to use the ESLint rule @typescript-eslint/strict-boolean-expressions, in order to prevent accidentally doing something like this:
    // Oops! Forgot to destructure here!
    const featureNewComponent = useLaika('new-component')
      
    // This will always be true since useLaika returns an array!
    if(featureNewComponent) {
      // ...
    }
      
    // This will always return a promise, so it's always true!
    if(getFeatureStatus('NEW_FEATURE', 'http://example.com', 'prod')) {
      // ...
    }

API

useLaika Hook

Fetches a flag from the Laika server and stores it in the components state.

Using a context allows you to skip the servers address and environment parameters and load them from the context instead.

function useLaika(
  feature: string,
  uri?: string,
  env?: string,
  cacheTimeout?: number,
): [boolean, boolean]

Parameter | Function ---|--- feature| The name of the feature flag on Laika uri | The uri to the laika service (for example https://laika.example.com env | The Laika env (for example test or prod) cacheTimeout | The time how long a requested flag should be cached (default: 1.5 minutes).The flags and cache timestamps are saved in localstorage. Return values | Returns an array with 2 entries:1. state: The current state of the flag (true or false, defaults to false while the request is still resolving)2. isLoading: The second entry is true if it's still requesting the flag from the server and false if it's finished loading (useful for displaying loading indicators for example)

Laika component

interface LaikaProps {
  feature: string
  env?: string
  uri?: string
  cacheTimeout?: number,
  onTrue: React.ReactElement | false
  onFalse: React.ReactElement | false
}

Works analog to the useLaika hook, except that it's a component. It will not render any children while the request is still loading the feature flag from Laika.

getFeatureStatus utility function

Retrieves the feature flag from the API and returns a promise that can be awaited.

The parameters are the same as in the useLaika hook.

async function getFeatureStatus(
  feature: string,
  uri: string,
  env: string,
  timeout?: number,
): Promise<boolean>

License

MIT Licensed. Copyright (c) Medigo GmbH 2025.