How to use Decisions in your React application

You can use DecisionLab Decisions in your React / Node / Nextjs app immediately.

NPM Package

We provide you with an NPM package that you can use to easily integrate DecisionLab in your application.

View package: React Package (npm)

Pre-requistes

In order to integrate DecisionLab in your application, you need:


Step 1: Install DecisionLab

npm i decisionlab

Step 2: Setup your React / Nextjs / Node App

DecisionLab requires a wrapper (DecisionProvider) in order to serve your app with your Decisions. We recommend setting the DecisionProvider as high as possible in the rendering tree of your application.

import { DecisionProvider } from "decisionlab";

const DECISION_LAB_CLIENT_KEY = "your_application_key"

...

const App = () => {
  return (
    <DecisionProvider clientKey={DECISION_LAB_CLIENT_KEY}>
      <MyAppProviders>Your app goes here</MyAppProviders>
    </DecisionProvider>
  );
};

Step 3: Use a Decision in your app

import { useDecision } from "decisionlab";

const MyComponent = () => {
  const value = useDecision("my_first_decision");
  return <div>My value is: {value}</div>;
};