25
loading...
This website collects cookies to deliver better user experience
npx create-react-app my-app
cd my-app
npm start
[{
name: 'banner',
description: 'Banner shown on top of the page',
active: false
}]
const initFeatures = () => {
if (!localStorage.getItem('flags')) {
localStorage.setItem('flags', JSON.stringify([
{name: 'banner', description: 'Banner shown on top of the page', active: false},
{name: 'reporting-yn', description: 'Switch on reporting modules for premium clients', active: false},
{name: 'info-message', description: 'Enhance info message with icon and link', active: true}
]));
}
};
const App = () => {
initFeatures();
...
}
const Feature = ({name, children}) => {
const features = JSON.parse(localStorage.getItem('flags'));
const feature = features.find(feature => feature.name === name);
if (feature && feature.active) {
return children;
}
return null;
};
export default Feature;
import Feature from './feature';
const App = () => {
initFeatures();
return (
<div className='App'>
<Feature name='banner'>
<Banner />
</Feature>
</div>
);
};
export default App;
npm install @flagship.io/react-sdk
import React from "react";
import { FlagshipProvider } from "@flagship.io/react-sdk";
const App = () => (
<>
<FlagshipProvider
envId="YOUR_ENV_ID"
apiKey="YOUR_API_KEY"
visitorData={{
id: "YOUR_VISITOR_ID",
context: {
// some context
},
isAuthenticated: false,
}}
enableConsoleLogs={true}
>
{/* [...] */}
</FlagshipProvider>
</>
);
import { useFlagship } from "@flagship.io/react-sdk";
export const MyReactComponent = () => {
const fsParams = {
modifications: {
requested: [
{
key: "btnColor", // btnColor is your flag identifier that should be declared in the Flagship UI
defaultValue: "green",
activate: false,
},
],
},
};
const {
modifications: fsModifications,
status: fsStatus,
hit: fsHit,
} = useFlagship(fsParams);
return (
<div
style={{
height: "200px",
width: "200px",
backgroundColor: modifications.backgroundColor,
}}
>
{"I'm a square with color=" + modifications.backgroundColor}
</div>
);
}