react-hook-toolkit 3.0.4 → 3.0.5

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.
@@ -34,7 +34,7 @@ interface ISpeakResult {
34
34
  isSupported: boolean;
35
35
  error: Error | null;
36
36
  }
37
- export declare function useSpeak(): ISpeakResult;
37
+ export declare const useSpeak: () => ISpeakResult;
38
38
  export declare function useCountUp(target: number, duration: number): {
39
39
  count: number;
40
40
  error: Error | null;
@@ -61,7 +61,7 @@ export function useCss(css) {
61
61
  return { error };
62
62
  }
63
63
  const IS_SUPPORTED = typeof window !== 'undefined' && 'speechSynthesis' in window;
64
- export function useSpeak() {
64
+ export const useSpeak = () => {
65
65
  const [status, setStatus] = useState('idle');
66
66
  const [error, setError] = useState(null);
67
67
  const isMounted = useRef(true);
@@ -135,7 +135,8 @@ export function useSpeak() {
135
135
  };
136
136
  // Cancel any ongoing speech
137
137
  window.speechSynthesis.cancel();
138
- setError(null);
138
+ if (isMounted.current)
139
+ setError(null);
139
140
  // Build utterance
140
141
  const utterance = new SpeechSynthesisUtterance(trimmed);
141
142
  utterance.rate = (_c = options.rate) !== null && _c !== void 0 ? _c : 1;
@@ -176,8 +177,13 @@ export function useSpeak() {
176
177
  (_b = (_a = callbacksRef.current).onError) === null || _b === void 0 ? void 0 : _b.call(_a, err);
177
178
  utteranceRef.current = null;
178
179
  };
180
+ // Assign ref BEFORE timeout — prevents Chrome GC dropping utterance mid-speech
179
181
  utteranceRef.current = utterance;
180
- window.speechSynthesis.speak(utterance);
182
+ // Chrome gets stuck in paused state after cancel() — delay lets it settle
183
+ setTimeout(() => {
184
+ if (isMounted.current)
185
+ window.speechSynthesis.speak(utterance);
186
+ }, 100);
181
187
  }, [safeSetStatus, safeSetError]); // minimal deps — text passed at call time
182
188
  return {
183
189
  speak,
@@ -190,7 +196,7 @@ export function useSpeak() {
190
196
  isSupported: IS_SUPPORTED,
191
197
  error,
192
198
  };
193
- }
199
+ };
194
200
  export function useCountUp(target, duration) {
195
201
  const [count, setCount] = useState(0);
196
202
  const [error, setError] = useState(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hook-toolkit",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "Ultimate package for React developers, offering a powerful collection of hooks and components to enhance their development experience.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",