@headband/react 0.1.0 → 0.1.1
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/dist/index.js +10 -4
- package/dist/index.mjs +10 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -157,12 +157,18 @@ function HeadbandProvider({
|
|
|
157
157
|
const [facets, setFacets] = (0, import_react.useState)(() => /* @__PURE__ */ new Set());
|
|
158
158
|
const timerRef = (0, import_react.useRef)(null);
|
|
159
159
|
const requestIdRef = (0, import_react.useRef)(0);
|
|
160
|
+
const refinementsRef = (0, import_react.useRef)(refinements);
|
|
161
|
+
refinementsRef.current = refinements;
|
|
162
|
+
const rangesRef = (0, import_react.useRef)(ranges);
|
|
163
|
+
rangesRef.current = ranges;
|
|
164
|
+
const facetsRef = (0, import_react.useRef)(facets);
|
|
165
|
+
facetsRef.current = facets;
|
|
160
166
|
const executeSearch = (0, import_react.useCallback)(() => {
|
|
161
167
|
const id = ++requestIdRef.current;
|
|
162
168
|
setIsLoading(true);
|
|
163
169
|
setError(null);
|
|
164
|
-
const filter = buildFilterString(
|
|
165
|
-
const facetList =
|
|
170
|
+
const filter = buildFilterString(refinementsRef.current, rangesRef.current);
|
|
171
|
+
const facetList = facetsRef.current.size > 0 ? Array.from(facetsRef.current) : void 0;
|
|
166
172
|
const sortList = sortBy ? [sortBy] : void 0;
|
|
167
173
|
const params = {
|
|
168
174
|
limit: hitsPerPage,
|
|
@@ -183,7 +189,7 @@ function HeadbandProvider({
|
|
|
183
189
|
setIsLoading(false);
|
|
184
190
|
}
|
|
185
191
|
});
|
|
186
|
-
}, [client, index, query,
|
|
192
|
+
}, [client, index, query, sortBy, page, hitsPerPage]);
|
|
187
193
|
(0, import_react.useEffect)(() => {
|
|
188
194
|
if (timerRef.current) {
|
|
189
195
|
clearTimeout(timerRef.current);
|
|
@@ -192,7 +198,7 @@ function HeadbandProvider({
|
|
|
192
198
|
return () => {
|
|
193
199
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
194
200
|
};
|
|
195
|
-
}, [executeSearch]);
|
|
201
|
+
}, [executeSearch, refinements, ranges, facets]);
|
|
196
202
|
const setQuery = (0, import_react.useCallback)((q) => {
|
|
197
203
|
setQueryRaw(q);
|
|
198
204
|
setPage(0);
|
package/dist/index.mjs
CHANGED
|
@@ -119,12 +119,18 @@ function HeadbandProvider({
|
|
|
119
119
|
const [facets, setFacets] = useState(() => /* @__PURE__ */ new Set());
|
|
120
120
|
const timerRef = useRef(null);
|
|
121
121
|
const requestIdRef = useRef(0);
|
|
122
|
+
const refinementsRef = useRef(refinements);
|
|
123
|
+
refinementsRef.current = refinements;
|
|
124
|
+
const rangesRef = useRef(ranges);
|
|
125
|
+
rangesRef.current = ranges;
|
|
126
|
+
const facetsRef = useRef(facets);
|
|
127
|
+
facetsRef.current = facets;
|
|
122
128
|
const executeSearch = useCallback(() => {
|
|
123
129
|
const id = ++requestIdRef.current;
|
|
124
130
|
setIsLoading(true);
|
|
125
131
|
setError(null);
|
|
126
|
-
const filter = buildFilterString(
|
|
127
|
-
const facetList =
|
|
132
|
+
const filter = buildFilterString(refinementsRef.current, rangesRef.current);
|
|
133
|
+
const facetList = facetsRef.current.size > 0 ? Array.from(facetsRef.current) : void 0;
|
|
128
134
|
const sortList = sortBy ? [sortBy] : void 0;
|
|
129
135
|
const params = {
|
|
130
136
|
limit: hitsPerPage,
|
|
@@ -145,7 +151,7 @@ function HeadbandProvider({
|
|
|
145
151
|
setIsLoading(false);
|
|
146
152
|
}
|
|
147
153
|
});
|
|
148
|
-
}, [client, index, query,
|
|
154
|
+
}, [client, index, query, sortBy, page, hitsPerPage]);
|
|
149
155
|
useEffect(() => {
|
|
150
156
|
if (timerRef.current) {
|
|
151
157
|
clearTimeout(timerRef.current);
|
|
@@ -154,7 +160,7 @@ function HeadbandProvider({
|
|
|
154
160
|
return () => {
|
|
155
161
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
156
162
|
};
|
|
157
|
-
}, [executeSearch]);
|
|
163
|
+
}, [executeSearch, refinements, ranges, facets]);
|
|
158
164
|
const setQuery = useCallback((q) => {
|
|
159
165
|
setQueryRaw(q);
|
|
160
166
|
setPage(0);
|