Skip to content

Commit 2b08344

Browse files
francoischalifourHaroenv
authored andcommitted
fix(pagination): update lifecycle state (#3979)
1 parent 8f05968 commit 2b08344

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

src/connectors/pagination/__tests__/connectPagination-test.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,45 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/pagination/
274274
const makeWidget = connectPagination(renderFn);
275275
const widget = makeWidget();
276276

277-
const nextConfiguation = widget.getConfiguration();
277+
const nextConfiguation = widget.getConfiguration(
278+
new SearchParameters({})
279+
);
280+
281+
expect(nextConfiguation).toEqual(
282+
new SearchParameters({
283+
page: 0,
284+
})
285+
);
286+
});
278287

279-
expect(nextConfiguation.page).toBe(0);
288+
it('takes the previous `page` from the `SearchParameters`', () => {
289+
const renderFn = () => {};
290+
const makeWidget = connectPagination(renderFn);
291+
const widget = makeWidget();
292+
293+
const nextConfiguation1 = widget.getConfiguration(
294+
new SearchParameters({
295+
page: 0,
296+
})
297+
);
298+
299+
expect(nextConfiguation1).toEqual(
300+
new SearchParameters({
301+
page: 0,
302+
})
303+
);
304+
305+
const nextConfiguation2 = widget.getConfiguration(
306+
new SearchParameters({
307+
page: 6,
308+
})
309+
);
310+
311+
expect(nextConfiguation2).toEqual(
312+
new SearchParameters({
313+
page: 6,
314+
})
315+
);
280316
});
281317
});
282318

src/connectors/pagination/connectPagination.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ export default function connectPagination(renderFn, unmountFn = noop) {
100100
return {
101101
$$type: 'ais.pagination',
102102

103-
getConfiguration() {
104-
return {
105-
page: 0,
106-
};
103+
getConfiguration(state) {
104+
return state.setQueryParameters({
105+
page: state.page || 0,
106+
});
107107
},
108108

109109
init({ helper, createURL, instantSearchInstance }) {

0 commit comments

Comments
 (0)