feature-flags-sdk
v0.1.1
Published
SDK to read feature flags in Node and React
Readme
feature-flags-sdk
SDK for consuming feature flags in Node.js and React apps.
Backed by feature-flags-core.
Install
npm install feature-flags-sdkFor React usage:
npm install react react-domNode / Server Usage
import { isFeatureEnabled } from "feature-flags-sdk"
if (isFeatureEnabled("newAPI")) {
console.log("Using new API")
}You can also use:
readFlags(cwd?)writeFlags(flags, cwd?)evaluateFlags(keys, cwd?)fetchRemoteFlags(url, init?)FLAG_FILENAME,getFlagFilePath(cwd?)
React Usage
import { useFeature } from "feature-flags-sdk/react"
export default function App() {
const newUI = useFeature("newUI")
return newUI ? <h1>New UI</h1> : <h1>Old UI</h1>
}useFeature(key, options?)
Options:
remoteUrl(default:"/.featureflags.json")pollIntervalMs(default:400)
The hook polls a JSON endpoint in the browser. Serve your flag file at that URL from your dev server or backend.
Example: custom endpoint
const beta = useFeature("betaCheckout", {
remoteUrl: "/api/feature-flags",
pollIntervalMs: 1000,
})