Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit 3527b94

Browse files
feat(hooks): introduce <Configure> (#3261)
1 parent b8b5d07 commit 3527b94

File tree

8 files changed

+55
-18
lines changed

8 files changed

+55
-18
lines changed

examples/hooks-ssr/src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import {
33
InstantSearch,
44
InstantSearchSSRProvider,
55
Index,
6+
Configure,
67
} from 'react-instantsearch-hooks';
78
import { simple } from 'instantsearch.js/es/lib/stateMappings';
89
import { history } from 'instantsearch.js/es/lib/routers';
910

1011
import { searchClient } from './searchClient';
1112

1213
import {
13-
Configure,
1414
Highlight,
1515
Hits,
1616
Pagination,

examples/hooks-ssr/src/components/Configure.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/hooks/App.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { Hit as AlgoliaHit } from '@algolia/client-search';
22
import algoliasearch from 'algoliasearch/lite';
33
import React from 'react';
4-
import { InstantSearch, DynamicWidgets } from 'react-instantsearch-hooks';
4+
import {
5+
InstantSearch,
6+
Configure,
7+
DynamicWidgets,
8+
} from 'react-instantsearch-hooks';
59

610
import {
711
ClearRefinements,
8-
Configure,
912
CurrentRefinements,
1013
HierarchicalMenu,
1114
Highlight,

examples/hooks/components/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export * from './ClearRefinements';
2-
export * from './Configure';
32
export * from './CurrentRefinements';
43
export * from './HierarchicalMenu';
54
export * from './Highlight';

examples/hooks/components/Configure.tsx renamed to packages/react-instantsearch-hooks/src/components/Configure.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { useConfigure, UseConfigureProps } from 'react-instantsearch-hooks';
1+
import { useConfigure } from '../connectors/useConfigure';
2+
3+
import type { UseConfigureProps } from '../connectors/useConfigure';
24

35
export type ConfigureProps = UseConfigureProps;
46

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { act, render, waitFor } from '@testing-library/react';
2+
import React from 'react';
3+
4+
import { createSearchClient } from '../../../../../test/mock';
5+
import { Configure } from '../Configure';
6+
import { InstantSearch } from '../InstantSearch';
7+
8+
describe('Configure', () => {
9+
test('does not render anything', () => {
10+
const searchClient = createSearchClient();
11+
12+
const { container } = render(
13+
<InstantSearch indexName="indexName" searchClient={searchClient}>
14+
<Configure hitsPerPage={666} />
15+
</InstantSearch>
16+
);
17+
18+
expect(container).toMatchInlineSnapshot(`<div />`);
19+
});
20+
21+
test('sets search parameters', async () => {
22+
const searchClient = createSearchClient();
23+
24+
act(() => {
25+
render(
26+
<InstantSearch indexName="indexName" searchClient={searchClient}>
27+
<Configure hitsPerPage={666} />
28+
</InstantSearch>
29+
);
30+
});
31+
32+
await waitFor(() => {
33+
expect(searchClient.search).toHaveBeenCalledTimes(1);
34+
expect(searchClient.search).toHaveBeenCalledWith([
35+
{
36+
indexName: 'indexName',
37+
params: expect.objectContaining({
38+
hitsPerPage: 666,
39+
}),
40+
},
41+
]);
42+
});
43+
});
44+
});

packages/react-instantsearch-hooks/src/components/__tests__/Index.test.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { render } from '@testing-library/react';
22
import React, { createRef } from 'react';
33

44
import { createSearchClient } from '../../../../../test/mock';
5-
import { useConfigure } from '../../connectors/useConfigure';
5+
import { Configure } from '../../components/Configure';
66
import { IndexContext } from '../../lib/IndexContext';
77
import { noop } from '../../lib/noop';
88
import { Index } from '../Index';
@@ -11,11 +11,6 @@ import { InstantSearchSSRProvider } from '../InstantSearchSSRProvider';
1111

1212
import type { IndexWidget } from 'instantsearch.js/es/widgets/index/index';
1313

14-
function Configure(props) {
15-
useConfigure(props);
16-
return null;
17-
}
18-
1914
describe('Index', () => {
2015
test('throws when used outside of <InstantSearch>', () => {
2116
// Hide the errors from the test logs.

packages/react-instantsearch-hooks/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { default as version } from './version';
2+
export * from './components/Configure';
23
export * from './components/DynamicWidgets';
34
export * from './components/Index';
45
export * from './components/InstantSearch';

0 commit comments

Comments
 (0)