React Native bindings for Quonfig.
This package is a thin polyfill wrapper around
@quonfig/react. It installs the two web APIs the
underlying JavaScript SDK assumes but React Native's JS runtime is missing (crypto.getRandomValues
and btoa / atob), then re-exports the entire @quonfig/react public API. If you need a feature
that the React SDK does not yet expose to React Native, open an issue.
npm install @quonfig/react-native @quonfig/react base-64 react-native-get-random-values
# or
yarn add @quonfig/react-native @quonfig/react base-64 react-native-get-random-valuesTypeScript types are included.
Identical to @quonfig/react — wrap your component
tree in QuonfigProvider and read flags with useQuonfig:
import { QuonfigProvider, useQuonfig } from "@quonfig/react-native";
const App = () => (
<QuonfigProvider
sdkKey="YOUR_SDK_KEY"
contextAttributes={{ user: { email: "jeffrey@example.com" } }}
onError={(err) => console.error(err)}
>
<Logo />
</QuonfigProvider>
);
const Logo = () => {
const { isEnabled } = useQuonfig();
return isEnabled("new-logo") ? <NewLogo /> : <OldLogo />;
};See the @quonfig/react README for the full API
(useQuonfig, useFlag, QuonfigTestProvider, etc.) and provider prop reference.
The entry point is ten lines:
import "react-native-get-random-values";
import { decode, encode } from "base-64";
if (typeof global.btoa === "undefined") {
global.btoa = encode;
}
if (typeof global.atob === "undefined") {
global.atob = decode;
}
export * from "@quonfig/react";react-native-get-random-valuespolyfillscrypto.getRandomValues(), which theuuidpackage (used by@quonfig/javascriptto generate the per-instance hash) requires.base-64providesbtoa/atob.@quonfig/javascript's base64 helper assumesbtoais available whenevertypeof window !== "undefined", which is true under React Native — but RN's JS runtime does not shipbtoanatively.
ISC