Retrieving Flags
Getting a single flag
//...start the SDK code
const visitor = Flagship.newVisitor({
visitorId: "your_visitor_id",
context: { isVip: true },
});
// Fetch flag from the Flagship platform
await visitor.fetchFlags();
// Retrieves a flag named "yourFlagKey"
const flag = visitor.getFlag("yourFlagKey");
//get the flag value, and if the flag is not found, returns the default value
console.log("flag value", flag.getValue("defaultValue"))import React from "react";
import { FlagshipProvider, useFsFlag } from "@flagship.io/react-sdk";
const App = () => (
<>
<FlagshipProvider
envId="<ENV_ID>"
apiKey="<API_KEY>"
visitorData={{
id: "<VISITOR_ID>",
hasConsented: true,
context: {
isVIP: true,
}
}}
>
<Component/>
</FlagshipProvider>
</>
);
const Component = () => {
// Retrieves a flag named "yourFlagKey"
const yourFlag = useFsFlag("yourFlagKey");
// Get the flag value, and if the flag is not found, returns the default value
const flagValue = yourFlag.getValue("defaultValue");
return (
<div>
<h1>My component</h1>
<p>Flag value: {flagValue}</p>
</div>
);
};Getting a collection of flags
Exposing flags
SDK
Last updated
Was this helpful?

