@splitlab/react 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +1 -0
- package/package.json +43 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var b=(e,t)=>{for(var r in t)u(e,r,{get:t[r],enumerable:!0})},S=(e,t,r,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of p(t))!f.call(e,n)&&n!==r&&u(e,n,{get:()=>t[n],enumerable:!(l=c(t,n))||l.enumerable});return e};var d=e=>S(u({},"__esModule",{value:!0}),e);var x={};b(x,{SplitLabProvider:()=>L,useFeatureFlag:()=>C,useSplitLab:()=>g,useVariant:()=>m});module.exports=d(x);var i=require("react"),s=require("@splitlab/js-client"),o=(0,i.createContext)(null);function L({config:e,children:t}){let[r,l]=(0,i.useState)(null),n=(0,i.useRef)(e);return(0,i.useEffect)(()=>{let a=new s.SplitLabClient(n.current);return a.initialize().then(()=>l(a)),()=>{a.destroy()}},[]),(0,i.createElement)(o.Provider,{value:r},t)}function g(){let e=(0,i.useContext)(o);if(!e)throw new Error("useSplitLab must be used within a <SplitLabProvider>. Make sure the provider has finished initializing.");return e}function m(e){let t=(0,i.useContext)(o);return t?t.getVariant(e):null}function C(e){let t=(0,i.useContext)(o);return t?t.isFeatureEnabled(e):!1}0&&(module.exports={SplitLabProvider,useFeatureFlag,useSplitLab,useVariant});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { SplitLabConfig, SplitLabClient } from '@splitlab/js-client';
|
|
4
|
+
|
|
5
|
+
interface SplitLabProviderProps {
|
|
6
|
+
config: SplitLabConfig;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
declare function SplitLabProvider({ config, children }: SplitLabProviderProps): react.FunctionComponentElement<react.ProviderProps<SplitLabClient | null>>;
|
|
10
|
+
declare function useSplitLab(): SplitLabClient;
|
|
11
|
+
declare function useVariant(experimentKey: string): string | null;
|
|
12
|
+
declare function useFeatureFlag(flagKey: string): boolean;
|
|
13
|
+
|
|
14
|
+
export { SplitLabProvider, type SplitLabProviderProps, useFeatureFlag, useSplitLab, useVariant };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { SplitLabConfig, SplitLabClient } from '@splitlab/js-client';
|
|
4
|
+
|
|
5
|
+
interface SplitLabProviderProps {
|
|
6
|
+
config: SplitLabConfig;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
declare function SplitLabProvider({ config, children }: SplitLabProviderProps): react.FunctionComponentElement<react.ProviderProps<SplitLabClient | null>>;
|
|
10
|
+
declare function useSplitLab(): SplitLabClient;
|
|
11
|
+
declare function useVariant(experimentKey: string): string | null;
|
|
12
|
+
declare function useFeatureFlag(flagKey: string): boolean;
|
|
13
|
+
|
|
14
|
+
export { SplitLabProvider, type SplitLabProviderProps, useFeatureFlag, useSplitLab, useVariant };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createElement as u,createContext as s,useContext as r,useEffect as c,useState as p,useRef as f}from"react";import{SplitLabClient as b}from"@splitlab/js-client";var i=s(null);function L({config:t,children:e}){let[l,o]=p(null),a=f(t);return c(()=>{let n=new b(a.current);return n.initialize().then(()=>o(n)),()=>{n.destroy()}},[]),u(i.Provider,{value:l},e)}function g(){let t=r(i);if(!t)throw new Error("useSplitLab must be used within a <SplitLabProvider>. Make sure the provider has finished initializing.");return t}function m(t){let e=r(i);return e?e.getVariant(t):null}function C(t){let e=r(i);return e?e.isFeatureEnabled(t):!1}export{L as SplitLabProvider,C as useFeatureFlag,g as useSplitLab,m as useVariant};
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@splitlab/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React bindings for SplitLab A/B testing and feature flags",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./dist/index.cjs",
|
|
11
|
+
"module": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/index.d.mts",
|
|
17
|
+
"default": "./dist/index.mjs"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"types": "./dist/index.d.cts",
|
|
21
|
+
"default": "./dist/index.cjs"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"dev": "tsup --watch"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@splitlab/js-client": "^0.1.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"react": ">=18"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/react": "^19.2.13",
|
|
40
|
+
"tsup": "^8.0.0",
|
|
41
|
+
"typescript": "^5.4.0"
|
|
42
|
+
}
|
|
43
|
+
}
|