@tramvai/state 1.79.0 → 1.82.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.
@@ -1,2 +1 @@
1
- import { useLayoutEffect } from 'react';
2
- export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
1
+ export { useIsomorphicLayoutEffect } from '@tinkoff/react-hooks';
package/lib/index.es.js CHANGED
@@ -6,10 +6,11 @@ import shallowEqual from '@tinkoff/utils/is/shallowEqual';
6
6
  import strictEqual from '@tinkoff/utils/is/strictEqual';
7
7
  import hoistStatics from 'hoist-non-react-statics';
8
8
  import invariant from 'invariant';
9
- import React, { createContext, useContext, useMemo, useLayoutEffect, useEffect, useRef, useReducer, useCallback } from 'react';
9
+ import React, { createContext, useContext, useMemo, useRef, useReducer, useCallback } from 'react';
10
10
  import { isValidElementType } from 'react-is';
11
11
  import isArray from '@tinkoff/utils/is/array';
12
- import { useShallowEqual } from '@tinkoff/react-hooks';
12
+ import { useShallowEqual, useIsomorphicLayoutEffect } from '@tinkoff/react-hooks';
13
+ export { useIsomorphicLayoutEffect } from '@tinkoff/react-hooks';
13
14
  import noop from '@tinkoff/utils/function/noop';
14
15
  import toArray from '@tinkoff/utils/array/toArray';
15
16
  import always from '@tinkoff/utils/function/always';
@@ -671,16 +672,6 @@ function useActions(actions) {
671
672
  }, [actionsRef, context]);
672
673
  }
673
674
 
674
- // React currently throws a warning when using useLayoutEffect on the server.
675
- // To get around it, we can conditionally useEffect on the server (no-op) and
676
- // useLayoutEffect in the browser. We need useLayoutEffect to ensure the store
677
- // subscription callback always has the selector from the latest render commit
678
- // available, otherwise a store update may happen between render and the effect,
679
- // which may cause missed updates; we also must ensure the store subscription
680
- // is created synchronously, otherwise a store update may occur before the
681
- // subscription is created and an inconsistent state may be observed
682
- const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
683
-
684
675
  function useStore(reducer) {
685
676
  const context = useConsumerContext();
686
677
  const reducerRef = useRef(reducer);
@@ -1380,4 +1371,4 @@ function createConnect({ connectHOC = connectAdvanced, mapStateToPropsFactories:
1380
1371
  const connect = /* @__PURE__ */ createConnect();
1381
1372
  const { Consumer } = ConnectContext;
1382
1373
 
1383
- export { BaseStore, ChildDispatcherContext, Consumer, Dispatcher, DispatcherContext, Provider, Subscription, connect, convertAction, createConnect, createDispatcher, createEvent, createReducer, index as devTools, useActions, useConsumerContext, useIsomorphicLayoutEffect, useSelector, useStore, useStoreSelector };
1374
+ export { BaseStore, ChildDispatcherContext, Consumer, Dispatcher, DispatcherContext, Provider, Subscription, connect, convertAction, createConnect, createDispatcher, createEvent, createReducer, index as devTools, useActions, useConsumerContext, useSelector, useStore, useStoreSelector };
package/lib/index.js CHANGED
@@ -694,16 +694,6 @@ function useActions(actions) {
694
694
  }, [actionsRef, context]);
695
695
  }
696
696
 
697
- // React currently throws a warning when using useLayoutEffect on the server.
698
- // To get around it, we can conditionally useEffect on the server (no-op) and
699
- // useLayoutEffect in the browser. We need useLayoutEffect to ensure the store
700
- // subscription callback always has the selector from the latest render commit
701
- // available, otherwise a store update may happen between render and the effect,
702
- // which may cause missed updates; we also must ensure the store subscription
703
- // is created synchronously, otherwise a store update may occur before the
704
- // subscription is created and an inconsistent state may be observed
705
- const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
706
-
707
697
  function useStore(reducer) {
708
698
  const context = useConsumerContext();
709
699
  const reducerRef = React.useRef(reducer);
@@ -718,7 +708,7 @@ function useStore(reducer) {
718
708
  addedReducerRef.current = reducer.storeName;
719
709
  }
720
710
  const stateRef = React.useRef(context.getState(reducer));
721
- useIsomorphicLayoutEffect(() => {
711
+ reactHooks.useIsomorphicLayoutEffect(() => {
722
712
  const subscribe = (updatedState) => {
723
713
  // если состояние текущего редьюсера изменилось,
724
714
  // обновляем локальное состояние и ререндерим компонент
@@ -788,12 +778,12 @@ function useSelector(storesOrStore, selector, equalityFn = shallowEqual__default
788
778
  }
789
779
  throw new Error(errorMessage);
790
780
  }
791
- useIsomorphicLayoutEffect(() => {
781
+ reactHooks.useIsomorphicLayoutEffect(() => {
792
782
  latestSelector.current = selector;
793
783
  latestSelectedState.current = selectedState;
794
784
  latestSubscriptionCallbackError.current = undefined;
795
785
  });
796
- useIsomorphicLayoutEffect(() => {
786
+ reactHooks.useIsomorphicLayoutEffect(() => {
797
787
  let didUnsubscribe = false;
798
788
  function checkForUpdates() {
799
789
  renderIsScheduled.current = false;
@@ -972,7 +962,7 @@ pure = true,
972
962
  // We need this to execute synchronously every time we re-render. However, React warns
973
963
  // about useLayoutEffect in SSR, so we try to detect environment and fall back to
974
964
  // just useEffect instead to avoid the warning, since neither will run anyway.
975
- useIsomorphicLayoutEffect(() => {
965
+ reactHooks.useIsomorphicLayoutEffect(() => {
976
966
  // We want to capture the wrapper props and child props we used for later comparisons
977
967
  lastWrapperProps.current = wrapperProps;
978
968
  lastChildProps.current = actualChildProps;
@@ -982,7 +972,7 @@ pure = true,
982
972
  }
983
973
  });
984
974
  // Our re-subscribe logic only runs when the store/subscription setup changes
985
- useIsomorphicLayoutEffect(() => {
975
+ reactHooks.useIsomorphicLayoutEffect(() => {
986
976
  // If we're not subscribed to the store, nothing to do here
987
977
  if (!subscription)
988
978
  return;
@@ -1403,6 +1393,10 @@ function createConnect({ connectHOC = connectAdvanced, mapStateToPropsFactories:
1403
1393
  const connect = /* @__PURE__ */ createConnect();
1404
1394
  const { Consumer } = ConnectContext;
1405
1395
 
1396
+ Object.defineProperty(exports, 'useIsomorphicLayoutEffect', {
1397
+ enumerable: true,
1398
+ get: function () { return reactHooks.useIsomorphicLayoutEffect; }
1399
+ });
1406
1400
  exports.BaseStore = BaseStore;
1407
1401
  exports.ChildDispatcherContext = ChildDispatcherContext;
1408
1402
  exports.Consumer = Consumer;
@@ -1419,7 +1413,6 @@ exports.createReducer = createReducer;
1419
1413
  exports.devTools = index;
1420
1414
  exports.useActions = useActions;
1421
1415
  exports.useConsumerContext = useConsumerContext;
1422
- exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
1423
1416
  exports.useSelector = useSelector;
1424
1417
  exports.useStore = useStore;
1425
1418
  exports.useStoreSelector = useStoreSelector;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/state",
3
- "version": "1.79.0",
3
+ "version": "1.82.2",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -18,9 +18,9 @@
18
18
  "build-for-publish": "true"
19
19
  },
20
20
  "dependencies": {
21
- "@tinkoff/react-hooks": "0.0.23",
21
+ "@tinkoff/react-hooks": "0.0.24",
22
22
  "@tinkoff/utils": "^2.1.2",
23
- "@tramvai/types-actions-state-context": "1.79.0",
23
+ "@tramvai/types-actions-state-context": "1.82.2",
24
24
  "@types/hoist-non-react-statics": "^3.3.1",
25
25
  "invariant": "^2.2.4",
26
26
  "react-is": ">=17",