useVariant

useVariant

This call’s variant of an experiment, or undefined where no variants are assigned (Goals and experiments).

import { useVariant } from "curb";

function useVariant(experiment: string): string | undefined;

Example

function Greeting() {
  const greeting = useVariant("greeting");
  return <Instruction>{greeting === "short" ? "Greet in three words." : "Greet warmly."}</Instruction>;
}

Version history

VersionChanges
v1.8.0useVariant introduced