@splitsoftware/splitio-react
Version:
A React library to easily integrate and use Split JS SDK
25 lines (24 loc) • 981 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSplitContext = exports.SplitContext = void 0;
var tslib_1 = require("tslib");
var React = (0, tslib_1.__importStar)(require("react"));
var constants_1 = require("./constants");
/**
* Split Context is the React Context instance provided by the SplitFactoryProvider and consumed by the Split Hooks.
* It is used to share the SDK factory instance and other values across the application.
*/
exports.SplitContext = React.createContext(undefined);
/**
* Hook to access the value of `SplitContext`.
*
* @returns The Split Context object value
* @throws Throws an error if the Split Context is not set (i.e. the component is not wrapped in a SplitFactoryProvider)
*/
function useSplitContext() {
var context = React.useContext(exports.SplitContext);
if (!context)
throw new Error(constants_1.EXCEPTION_NO_SFP);
return context;
}
exports.useSplitContext = useSplitContext;
;