@faststats/react 0.5.0 → 0.6.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.
Files changed (2) hide show
  1. package/dist/index.js +25 -18
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ function setInstance(wa) {
20
20
  //#endregion
21
21
  //#region src/analytics.tsx
22
22
  const SDK_NAME = "@faststats/react";
23
- const SDK_VERSION = "0.5.0";
23
+ const SDK_VERSION = "0.6.0";
24
24
  function Analytics(props) {
25
25
  const ownedRef = useRef(null);
26
26
  const propsRef = useRef(props);
@@ -80,16 +80,21 @@ function useOptOut() {
80
80
  }
81
81
  //#endregion
82
82
  //#region src/use-flag.ts
83
- const defaultEvaluation = { value: "false" };
83
+ const defaultState = {
84
+ value: "false",
85
+ isLoading: false,
86
+ error: null
87
+ };
84
88
  let hasWarnedAboutMissingInstance = false;
85
89
  function useFlag(flagKey, options) {
86
90
  const wa = useSyncExternalStore(subscribeToInstance, getInstanceSnapshot, () => null);
87
91
  const attributes = options?.attributes;
88
92
  const externalId = options?.externalId;
89
93
  const skip = options?.skip ?? false;
90
- const [evaluation, setEvaluation] = useState(defaultEvaluation);
91
- const [isLoading, setIsLoading] = useState(!skip);
92
- const [error, setError] = useState(null);
94
+ const [state, setState] = useState({
95
+ ...defaultState,
96
+ isLoading: !skip
97
+ });
93
98
  const abortRef = useRef(null);
94
99
  const fetchFlag = useCallback(() => {
95
100
  abortRef.current?.abort();
@@ -99,29 +104,33 @@ function useFlag(flagKey, options) {
99
104
  hasWarnedAboutMissingInstance = true;
100
105
  console.warn("[faststats/react] useFlag requires an active <Analytics /> instance.");
101
106
  }
102
- setIsLoading(false);
103
- setEvaluation(defaultEvaluation);
104
- setError(null);
107
+ setState(defaultState);
105
108
  return;
106
109
  }
107
110
  const ac = new AbortController();
108
111
  abortRef.current = ac;
109
- setIsLoading(true);
110
- setError(null);
112
+ setState({
113
+ ...defaultState,
114
+ isLoading: true
115
+ });
111
116
  wa.checkFeatureFlag(flagKey, attributes, {
112
117
  externalId,
113
118
  signal: ac.signal
114
119
  }).then((result) => {
115
120
  if (ac.signal.aborted) return;
116
- setEvaluation(result);
117
- setIsLoading(false);
121
+ setState({
122
+ ...result,
123
+ isLoading: false,
124
+ error: null
125
+ });
118
126
  }).catch((e) => {
119
127
  if (ac.signal.aborted) return;
120
128
  const err = e instanceof Error ? e : new Error(String(e));
121
129
  if (err.name === "AbortError") return;
122
- setError(err);
123
- setEvaluation(defaultEvaluation);
124
- setIsLoading(false);
130
+ setState({
131
+ ...defaultState,
132
+ error: err
133
+ });
125
134
  });
126
135
  }, [
127
136
  wa,
@@ -137,9 +146,7 @@ function useFlag(flagKey, options) {
137
146
  };
138
147
  }, [fetchFlag]);
139
148
  return {
140
- ...evaluation,
141
- isLoading,
142
- error,
149
+ ...state,
143
150
  refetch: fetchFlag
144
151
  };
145
152
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "https://github.com/faststats-dev/faststats-javascript.git"
6
6
  },
7
- "version": "0.5.0",
7
+ "version": "0.6.0",
8
8
  "type": "module",
9
9
  "main": "./dist/index.js",
10
10
  "module": "./dist/index.js",
@@ -31,7 +31,7 @@
31
31
  "react": ">=18"
32
32
  },
33
33
  "dependencies": {
34
- "@faststats/web": "^0.5.0"
34
+ "@faststats/web": "^0.6.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "^25.9.3",