react-instantsearch-core 7.24.0 → 7.26.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 (140) hide show
  1. package/dist/cjs/components/Configure.js +11 -17
  2. package/dist/cjs/components/DynamicWidgets.js +46 -53
  3. package/dist/cjs/components/Index.js +19 -22
  4. package/dist/cjs/components/InstantSearch.js +34 -36
  5. package/dist/cjs/components/InstantSearchSSRProvider.js +31 -41
  6. package/dist/cjs/components/InstantSearchServerContext.js +6 -10
  7. package/dist/cjs/connectors/useAutocomplete.js +8 -10
  8. package/dist/cjs/connectors/useBreadcrumb.js +8 -10
  9. package/dist/cjs/connectors/useChat.js +8 -10
  10. package/dist/cjs/connectors/useClearRefinements.js +8 -10
  11. package/dist/cjs/connectors/useConfigure.js +10 -12
  12. package/dist/cjs/connectors/useCurrentRefinements.js +8 -10
  13. package/dist/cjs/connectors/useDynamicWidgets.js +14 -20
  14. package/dist/cjs/connectors/useFilterSuggestions.js +8 -10
  15. package/dist/cjs/connectors/useFrequentlyBoughtTogether.js +8 -10
  16. package/dist/cjs/connectors/useGeoSearch.js +8 -10
  17. package/dist/cjs/connectors/useHierarchicalMenu.js +8 -10
  18. package/dist/cjs/connectors/useHits.js +8 -10
  19. package/dist/cjs/connectors/useHitsPerPage.js +8 -10
  20. package/dist/cjs/connectors/useInfiniteHits.js +8 -10
  21. package/dist/cjs/connectors/useLookingSimilar.js +8 -10
  22. package/dist/cjs/connectors/useMenu.js +8 -10
  23. package/dist/cjs/connectors/useNumericMenu.js +8 -10
  24. package/dist/cjs/connectors/usePagination.js +8 -10
  25. package/dist/cjs/connectors/usePoweredBy.js +18 -19
  26. package/dist/cjs/connectors/useQueryRules.js +8 -10
  27. package/dist/cjs/connectors/useRange.js +8 -10
  28. package/dist/cjs/connectors/useRefinementList.js +8 -10
  29. package/dist/cjs/connectors/useRelatedProducts.js +8 -10
  30. package/dist/cjs/connectors/useSearchBox.js +8 -10
  31. package/dist/cjs/connectors/useSortBy.js +8 -10
  32. package/dist/cjs/connectors/useStats.js +8 -10
  33. package/dist/cjs/connectors/useToggleRefinement.js +8 -10
  34. package/dist/cjs/connectors/useTrendingItems.js +8 -10
  35. package/dist/cjs/hooks/useConnector.js +123 -139
  36. package/dist/cjs/hooks/useInstantSearch.js +59 -59
  37. package/dist/cjs/index.js +90 -519
  38. package/dist/cjs/lib/IndexContext.js +6 -10
  39. package/dist/cjs/lib/InstantSearchContext.js +6 -10
  40. package/dist/cjs/lib/InstantSearchRSCContext.js +11 -12
  41. package/dist/cjs/lib/InstantSearchSSRContext.js +6 -10
  42. package/dist/cjs/lib/createSearchResults.js +24 -25
  43. package/dist/cjs/lib/dequal.js +33 -40
  44. package/dist/cjs/lib/getIndexSearchResults.js +23 -30
  45. package/dist/cjs/lib/invariant.js +11 -17
  46. package/dist/cjs/lib/noop.js +8 -6
  47. package/dist/cjs/lib/use.js +26 -11
  48. package/dist/cjs/lib/useAppIdAndApiKey.js +10 -12
  49. package/dist/cjs/lib/useForceUpdate.js +12 -21
  50. package/dist/cjs/lib/useIndex.js +40 -37
  51. package/dist/cjs/lib/useIndexContext.js +11 -12
  52. package/dist/cjs/lib/useInstantSearchApi.js +174 -197
  53. package/dist/cjs/lib/useInstantSearchContext.js +11 -12
  54. package/dist/cjs/lib/useInstantSearchSSRContext.js +8 -9
  55. package/dist/cjs/lib/useInstantSearchServerContext.js +8 -9
  56. package/dist/cjs/lib/useIsomorphicLayoutEffect.js +6 -8
  57. package/dist/cjs/lib/useRSCContext.js +8 -9
  58. package/dist/cjs/lib/useSearchResults.js +54 -62
  59. package/dist/cjs/lib/useSearchState.js +53 -60
  60. package/dist/cjs/lib/useStableValue.js +15 -24
  61. package/dist/cjs/lib/useWidget.js +99 -95
  62. package/dist/cjs/lib/warn.js +11 -35
  63. package/dist/cjs/lib/wrapPromiseWithState.js +23 -26
  64. package/dist/cjs/package.json +4 -1
  65. package/dist/cjs/server/getServerState.js +81 -91
  66. package/dist/cjs/server/index.js +6 -15
  67. package/dist/cjs/version.js +6 -6
  68. package/dist/es/components/Configure.js +11 -13
  69. package/dist/es/components/DynamicWidgets.js +45 -47
  70. package/dist/es/components/Index.js +19 -17
  71. package/dist/es/components/InstantSearch.js +33 -29
  72. package/dist/es/components/InstantSearchSSRProvider.js +30 -35
  73. package/dist/es/components/InstantSearchServerContext.js +4 -4
  74. package/dist/es/connectors/useAutocomplete.js +8 -5
  75. package/dist/es/connectors/useBreadcrumb.js +8 -5
  76. package/dist/es/connectors/useChat.js +8 -5
  77. package/dist/es/connectors/useClearRefinements.js +8 -5
  78. package/dist/es/connectors/useConfigure.js +10 -7
  79. package/dist/es/connectors/useCurrentRefinements.js +8 -5
  80. package/dist/es/connectors/useDynamicWidgets.js +14 -15
  81. package/dist/es/connectors/useFilterSuggestions.js +8 -5
  82. package/dist/es/connectors/useFrequentlyBoughtTogether.js +8 -5
  83. package/dist/es/connectors/useGeoSearch.js +8 -5
  84. package/dist/es/connectors/useHierarchicalMenu.js +8 -5
  85. package/dist/es/connectors/useHits.js +8 -5
  86. package/dist/es/connectors/useHitsPerPage.js +8 -5
  87. package/dist/es/connectors/useInfiniteHits.js +8 -5
  88. package/dist/es/connectors/useLookingSimilar.js +8 -5
  89. package/dist/es/connectors/useMenu.js +8 -5
  90. package/dist/es/connectors/useNumericMenu.js +8 -5
  91. package/dist/es/connectors/usePagination.js +8 -5
  92. package/dist/es/connectors/usePoweredBy.js +18 -15
  93. package/dist/es/connectors/useQueryRules.js +8 -5
  94. package/dist/es/connectors/useRange.js +8 -5
  95. package/dist/es/connectors/useRefinementList.js +8 -5
  96. package/dist/es/connectors/useRelatedProducts.js +8 -5
  97. package/dist/es/connectors/useSearchBox.js +8 -5
  98. package/dist/es/connectors/useSortBy.js +8 -5
  99. package/dist/es/connectors/useStats.js +8 -5
  100. package/dist/es/connectors/useToggleRefinement.js +8 -5
  101. package/dist/es/connectors/useTrendingItems.js +8 -5
  102. package/dist/es/hooks/useConnector.js +122 -134
  103. package/dist/es/hooks/useInstantSearch.js +58 -54
  104. package/dist/es/index.js +43 -43
  105. package/dist/es/lib/IndexContext.js +4 -4
  106. package/dist/es/lib/InstantSearchContext.js +4 -4
  107. package/dist/es/lib/InstantSearchRSCContext.js +10 -7
  108. package/dist/es/lib/InstantSearchSSRContext.js +4 -4
  109. package/dist/es/lib/createSearchResults.js +23 -19
  110. package/dist/es/lib/dequal.js +33 -36
  111. package/dist/es/lib/getIndexSearchResults.js +23 -26
  112. package/dist/es/lib/invariant.js +10 -12
  113. package/dist/es/lib/noop.js +7 -1
  114. package/dist/es/lib/use.js +4 -2
  115. package/dist/es/lib/useAppIdAndApiKey.js +9 -7
  116. package/dist/es/lib/useForceUpdate.js +9 -15
  117. package/dist/es/lib/useIndex.js +39 -31
  118. package/dist/es/lib/useIndexContext.js +10 -7
  119. package/dist/es/lib/useInstantSearchApi.js +174 -191
  120. package/dist/es/lib/useInstantSearchContext.js +10 -7
  121. package/dist/es/lib/useInstantSearchSSRContext.js +7 -4
  122. package/dist/es/lib/useInstantSearchServerContext.js +7 -4
  123. package/dist/es/lib/useIsomorphicLayoutEffect.js +4 -3
  124. package/dist/es/lib/useRSCContext.js +7 -4
  125. package/dist/es/lib/useSearchResults.js +53 -57
  126. package/dist/es/lib/useSearchState.js +52 -55
  127. package/dist/es/lib/useStableValue.js +14 -19
  128. package/dist/es/lib/useWidget.js +98 -90
  129. package/dist/es/lib/warn.js +9 -29
  130. package/dist/es/lib/wrapPromiseWithState.js +23 -22
  131. package/dist/es/package.json +4 -0
  132. package/dist/es/server/getServerState.js +80 -85
  133. package/dist/es/server/index.js +1 -1
  134. package/dist/es/version.d.ts +1 -1
  135. package/dist/es/version.js +3 -1
  136. package/dist/umd/ReactInstantSearchCore.js +17488 -22329
  137. package/dist/umd/ReactInstantSearchCore.min.js +3 -3
  138. package/package.json +7 -11
  139. package/dist/umd/ReactInstantSearchCore.js.map +0 -1
  140. package/dist/umd/ReactInstantSearchCore.min.js.map +0 -1
@@ -1,47 +1,44 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- /* eslint-disable complexity */
1
+ import { _ } from '@swc/helpers/cjs/_type_of.cjs';
3
2
 
4
- /*
3
+ /* eslint-disable complexity */ /*
5
4
  * Code taken from dequal/lite v2.0.0
6
5
  * https://github.com/lukeed/dequal/blob/9aa73181ac7e081cd330cac67d313632ac04bb02/src/lite.js
7
6
  *
8
7
  * It adds a 3rd argument `compare(a, b)` that lets execute custom logic to
9
8
  * compare values.
10
9
  * We use it to skip comparing function references.
11
- */
12
-
13
- // eslint-disable-next-line @typescript-eslint/unbound-method
10
+ */ // eslint-disable-next-line @typescript-eslint/unbound-method
14
11
  var has = Object.prototype.hasOwnProperty;
15
- export function dequal(foo, bar, compare) {
16
- // start of custom implementation
17
- if (compare !== null && compare !== void 0 && compare(foo, bar)) {
18
- return true;
19
- }
20
- // end of custom implementation
21
-
22
- var ctor;
23
- var len;
24
- if (foo === bar) return true;
25
- if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
26
- if (ctor === Date) return foo.getTime() === bar.getTime();
27
- if (ctor === RegExp) return foo.toString() === bar.toString();
28
- if (ctor === Array) {
29
- if ((len = foo.length) === bar.length) {
30
- while (len-- && dequal(foo[len], bar[len], compare));
31
- }
32
- return len === -1;
12
+ function dequal(foo, bar, compare) {
13
+ // start of custom implementation
14
+ if (compare === null || compare === void 0 ? void 0 : compare(foo, bar)) {
15
+ return true;
33
16
  }
34
- if (!ctor || _typeof(foo) === 'object') {
35
- len = 0;
36
- // eslint-disable-next-line guard-for-in, no-restricted-syntax
37
- for (ctor in foo) {
38
- if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
39
- if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor], compare)) return false;
40
- }
41
- return Object.keys(bar).length === len;
17
+ // end of custom implementation
18
+ var ctor;
19
+ var len;
20
+ if (foo === bar) return true;
21
+ if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
22
+ if (ctor === Date) return foo.getTime() === bar.getTime();
23
+ if (ctor === RegExp) return foo.toString() === bar.toString();
24
+ if (ctor === Array) {
25
+ if ((len = foo.length) === bar.length) {
26
+ while(len-- && dequal(foo[len], bar[len], compare));
27
+ }
28
+ return len === -1;
29
+ }
30
+ if (!ctor || (typeof foo === "undefined" ? "undefined" : _(foo)) === 'object') {
31
+ len = 0;
32
+ // eslint-disable-next-line guard-for-in, no-restricted-syntax
33
+ for(ctor in foo){
34
+ if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
35
+ if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor], compare)) return false;
36
+ }
37
+ return Object.keys(bar).length === len;
38
+ }
42
39
  }
43
- }
40
+ // eslint-disable-next-line no-self-compare
41
+ return foo !== foo && bar !== bar;
42
+ }
44
43
 
45
- // eslint-disable-next-line no-self-compare
46
- return foo !== foo && bar !== bar;
47
- }
44
+ export { dequal };
@@ -1,27 +1,24 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
5
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
- import { createSearchResults } from "./createSearchResults.js";
8
- export function getIndexSearchResults(indexWidget) {
9
- var helper = indexWidget.getHelper();
10
- var results =
11
- // On SSR, we get the results injected on the Index.
12
- indexWidget.getResults() ||
13
- // On the browser, we create fallback results based on the helper state.
14
- createSearchResults(helper.state);
15
- var scopedResults = indexWidget.getScopedResults().map(function (scopedResult) {
16
- var fallbackResults = scopedResult.indexId === indexWidget.getIndexId() ? results : createSearchResults(scopedResult.helper.state);
17
- return _objectSpread(_objectSpread({}, scopedResult), {}, {
18
- // We keep `results` from being `null`.
19
- results: scopedResult.results || fallbackResults
1
+ import { _ as _$1 } from '@swc/helpers/cjs/_object_spread.cjs';
2
+ import { _ } from '@swc/helpers/cjs/_object_spread_props.cjs';
3
+ import { createSearchResults } from './createSearchResults.js';
4
+
5
+ function getIndexSearchResults(indexWidget) {
6
+ var helper = indexWidget.getHelper();
7
+ var results = // On SSR, we get the results injected on the Index.
8
+ indexWidget.getResults() || // On the browser, we create fallback results based on the helper state.
9
+ createSearchResults(helper.state);
10
+ var scopedResults = indexWidget.getScopedResults().map(function(scopedResult) {
11
+ var fallbackResults = scopedResult.indexId === indexWidget.getIndexId() ? results : createSearchResults(scopedResult.helper.state);
12
+ return _(_$1({}, scopedResult), {
13
+ // We keep `results` from being `null`.
14
+ results: scopedResult.results || fallbackResults
15
+ });
20
16
  });
21
- });
22
- return {
23
- results: results,
24
- scopedResults: scopedResults,
25
- recommendResults: helper.lastRecommendResults
26
- };
27
- }
17
+ return {
18
+ results: results,
19
+ scopedResults: scopedResults,
20
+ recommendResults: helper.lastRecommendResults
21
+ };
22
+ }
23
+
24
+ export { getIndexSearchResults };
@@ -5,15 +5,13 @@
5
5
  *
6
6
  * This is used to make development a better experience to provide guidance as
7
7
  * to where the error comes from.
8
- */
9
- export function invariant(condition, message) {
10
- if (condition) {
11
- return;
12
- }
13
- if (!(process.env.NODE_ENV === 'development')) {
14
- throw new Error('Invariant failed');
15
- }
16
- if (process.env.NODE_ENV === 'development') {
17
- throw new Error("[InstantSearch] ".concat(typeof message === 'function' ? message() : message));
18
- }
19
- }
8
+ */ function invariant(condition, message) {
9
+ if (condition) {
10
+ return;
11
+ }
12
+ {
13
+ throw new Error('Invariant failed');
14
+ }
15
+ }
16
+
17
+ export { invariant };
@@ -1 +1,7 @@
1
- export var noop = function noop() {};
1
+ var noop = function noop() {
2
+ for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){
3
+ _args[_key] = arguments[_key];
4
+ }
5
+ };
6
+
7
+ export { noop };
@@ -1,5 +1,7 @@
1
1
  import * as React from 'react';
2
- var useKey = 'use';
3
2
 
3
+ var useKey = 'use';
4
4
  // @TODO: Remove this file and import directly from React when available.
5
- export var use = React[useKey];
5
+ var use = React[useKey];
6
+
7
+ export { use };
@@ -1,7 +1,9 @@
1
- import { getAppIdAndApiKey } from "instantsearch.js/es/lib/utils/index.js";
2
- import { useInstantSearchContext } from "./useInstantSearchContext.js";
3
- export var useAppIdAndApiKey = function useAppIdAndApiKey() {
4
- var _useInstantSearchCont = useInstantSearchContext(),
5
- client = _useInstantSearchCont.client;
6
- return getAppIdAndApiKey(client);
7
- };
1
+ import { getAppIdAndApiKey } from 'instantsearch.js/es/lib/utils/index.js';
2
+ import { useInstantSearchContext } from './useInstantSearchContext.js';
3
+
4
+ var useAppIdAndApiKey = function useAppIdAndApiKey() {
5
+ var client = useInstantSearchContext().client;
6
+ return getAppIdAndApiKey(client);
7
+ };
8
+
9
+ export { useAppIdAndApiKey };
@@ -1,20 +1,14 @@
1
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
2
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
1
+ import { _ } from '@swc/helpers/cjs/_sliced_to_array.cjs';
7
2
  import { useReducer } from 'react';
8
3
 
9
4
  /**
10
5
  * Forces a React update that triggers a rerender.
11
6
  * @link https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate
12
- */
13
- export function useForceUpdate() {
14
- var _useReducer = useReducer(function (x) {
15
- return x + 1;
16
- }, 0),
17
- _useReducer2 = _slicedToArray(_useReducer, 2),
18
- forceUpdate = _useReducer2[1];
19
- return forceUpdate;
20
- }
7
+ */ function useForceUpdate() {
8
+ var _useReducer = _(useReducer(function(x) {
9
+ return x + 1;
10
+ }, 0), 2), forceUpdate = _useReducer[1];
11
+ return forceUpdate;
12
+ }
13
+
14
+ export { useForceUpdate };
@@ -1,32 +1,40 @@
1
- import index from "instantsearch.js/es/widgets/index/index.js";
1
+ import index from 'instantsearch.js/es/widgets/index/index.js';
2
2
  import { useMemo } from 'react';
3
- import { useForceUpdate } from "./useForceUpdate.js";
4
- import { useIndexContext } from "./useIndexContext.js";
5
- import { useInstantSearchServerContext } from "./useInstantSearchServerContext.js";
6
- import { useInstantSearchSSRContext } from "./useInstantSearchSSRContext.js";
7
- import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.js";
8
- import { useStableValue } from "./useStableValue.js";
9
- import { useWidget } from "./useWidget.js";
10
- export function useIndex(props) {
11
- var serverContext = useInstantSearchServerContext();
12
- var ssrContext = useInstantSearchSSRContext();
13
- var initialResults = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.initialResults;
14
- var parentIndex = useIndexContext();
15
- var stableProps = useStableValue(props);
16
- var indexWidget = useMemo(function () {
17
- return index(stableProps);
18
- }, [stableProps]);
19
- var helper = indexWidget.getHelper();
20
- var forceUpdate = useForceUpdate();
21
- useIsomorphicLayoutEffect(function () {
22
- forceUpdate();
23
- }, [helper, forceUpdate]);
24
- useWidget({
25
- widget: indexWidget,
26
- parentIndex: parentIndex,
27
- props: stableProps,
28
- shouldSsr: Boolean(serverContext || initialResults),
29
- skipSuspense: true
30
- });
31
- return indexWidget;
32
- }
3
+ import { useForceUpdate } from './useForceUpdate.js';
4
+ import { useIndexContext } from './useIndexContext.js';
5
+ import { useInstantSearchServerContext } from './useInstantSearchServerContext.js';
6
+ import { useInstantSearchSSRContext } from './useInstantSearchSSRContext.js';
7
+ import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect.js';
8
+ import { useStableValue } from './useStableValue.js';
9
+ import { useWidget } from './useWidget.js';
10
+
11
+ function useIndex(props) {
12
+ var serverContext = useInstantSearchServerContext();
13
+ var ssrContext = useInstantSearchSSRContext();
14
+ var initialResults = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.initialResults;
15
+ var parentIndex = useIndexContext();
16
+ var stableProps = useStableValue(props);
17
+ var indexWidget = useMemo(function() {
18
+ return index(stableProps);
19
+ }, [
20
+ stableProps
21
+ ]);
22
+ var helper = indexWidget.getHelper();
23
+ var forceUpdate = useForceUpdate();
24
+ useIsomorphicLayoutEffect(function() {
25
+ forceUpdate();
26
+ }, [
27
+ helper,
28
+ forceUpdate
29
+ ]);
30
+ useWidget({
31
+ widget: indexWidget,
32
+ parentIndex: parentIndex,
33
+ props: stableProps,
34
+ shouldSsr: Boolean(serverContext || initialResults),
35
+ skipSuspense: true
36
+ });
37
+ return indexWidget;
38
+ }
39
+
40
+ export { useIndex };
@@ -1,8 +1,11 @@
1
1
  import { useContext } from 'react';
2
- import { IndexContext } from "./IndexContext.js";
3
- import { invariant } from "./invariant.js";
4
- export function useIndexContext() {
5
- var context = useContext(IndexContext);
6
- invariant(context !== null, 'The <Index> component must be used within <InstantSearch>.');
7
- return context;
8
- }
2
+ import { IndexContext } from './IndexContext.js';
3
+ import { invariant } from './invariant.js';
4
+
5
+ function useIndexContext() {
6
+ var context = useContext(IndexContext);
7
+ invariant(context !== null);
8
+ return context;
9
+ }
10
+
11
+ export { useIndexContext };