react-realtime-hooks 1.4.1 → 1.4.2
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/README.md +14 -0
- package/dist/index.cjs +12 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useSyncExternalStore, useRef, useState, useEffect,
|
|
1
|
+
import { useSyncExternalStore, useRef, useState, useEffect, useInsertionEffect, useMemo, useCallback } from 'react';
|
|
2
2
|
|
|
3
3
|
// src/hooks/useOnlineStatus.ts
|
|
4
4
|
|
|
@@ -464,7 +464,9 @@ var useReconnect = (options = {}) => {
|
|
|
464
464
|
() => createInitialState(normalizedOptions.enabled)
|
|
465
465
|
);
|
|
466
466
|
const stateRef = useRef(state);
|
|
467
|
-
|
|
467
|
+
useInsertionEffect(() => {
|
|
468
|
+
stateRef.current = state;
|
|
469
|
+
});
|
|
468
470
|
const commitState = (next) => {
|
|
469
471
|
const resolved = typeof next === "function" ? next(stateRef.current) : next;
|
|
470
472
|
stateRef.current = resolved;
|
|
@@ -597,7 +599,9 @@ var useHeartbeat = (options) => {
|
|
|
597
599
|
() => createInitialState2(enabled && startOnMount)
|
|
598
600
|
);
|
|
599
601
|
const stateRef = useRef(state);
|
|
600
|
-
|
|
602
|
+
useInsertionEffect(() => {
|
|
603
|
+
stateRef.current = state;
|
|
604
|
+
});
|
|
601
605
|
const commitState = (next) => {
|
|
602
606
|
const resolved = typeof next === "function" ? next(stateRef.current) : next;
|
|
603
607
|
stateRef.current = resolved;
|
|
@@ -940,7 +944,9 @@ var useWebSocket = (options) => {
|
|
|
940
944
|
() => createInitialState4(connect ? "connecting" : "idle")
|
|
941
945
|
);
|
|
942
946
|
const stateRef = useRef(state);
|
|
943
|
-
|
|
947
|
+
useInsertionEffect(() => {
|
|
948
|
+
stateRef.current = state;
|
|
949
|
+
});
|
|
944
950
|
const reconnectEnabled = options.reconnect !== false && supported && resolvedUrl !== null;
|
|
945
951
|
const reconnect = useReconnect(
|
|
946
952
|
options.reconnect === false ? { enabled: false } : {
|
|
@@ -1513,7 +1519,9 @@ var useEventSource = (options) => {
|
|
|
1513
1519
|
() => createInitialState5(connect ? "connecting" : "idle")
|
|
1514
1520
|
);
|
|
1515
1521
|
const stateRef = useRef(state);
|
|
1516
|
-
|
|
1522
|
+
useInsertionEffect(() => {
|
|
1523
|
+
stateRef.current = state;
|
|
1524
|
+
});
|
|
1517
1525
|
const reconnectEnabled = options.reconnect !== false && supported && resolvedUrl !== null;
|
|
1518
1526
|
const reconnect = useReconnect(
|
|
1519
1527
|
options.reconnect === false ? { enabled: false } : {
|