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

Commit

Permalink
feat(hooks): introduce <Configure> (#3261)
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Jan 17, 2022
1 parent b8b5d07 commit 3527b94
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 18 deletions.
2 changes: 1 addition & 1 deletion examples/hooks-ssr/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {
InstantSearch,
InstantSearchSSRProvider,
Index,
Configure,
} from 'react-instantsearch-hooks';
import { simple } from 'instantsearch.js/es/lib/stateMappings';
import { history } from 'instantsearch.js/es/lib/routers';

import { searchClient } from './searchClient';

import {
Configure,
Highlight,
Hits,
Pagination,
Expand Down
7 changes: 0 additions & 7 deletions examples/hooks-ssr/src/components/Configure.js

This file was deleted.

7 changes: 5 additions & 2 deletions examples/hooks/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Hit as AlgoliaHit } from '@algolia/client-search';
import algoliasearch from 'algoliasearch/lite';
import React from 'react';
import { InstantSearch, DynamicWidgets } from 'react-instantsearch-hooks';
import {
InstantSearch,
Configure,
DynamicWidgets,
} from 'react-instantsearch-hooks';

import {
ClearRefinements,
Configure,
CurrentRefinements,
HierarchicalMenu,
Highlight,
Expand Down
1 change: 0 additions & 1 deletion examples/hooks/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './ClearRefinements';
export * from './Configure';
export * from './CurrentRefinements';
export * from './HierarchicalMenu';
export * from './Highlight';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useConfigure, UseConfigureProps } from 'react-instantsearch-hooks';
import { useConfigure } from '../connectors/useConfigure';

import type { UseConfigureProps } from '../connectors/useConfigure';

export type ConfigureProps = UseConfigureProps;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { act, render, waitFor } from '@testing-library/react';
import React from 'react';

import { createSearchClient } from '../../../../../test/mock';
import { Configure } from '../Configure';
import { InstantSearch } from '../InstantSearch';

describe('Configure', () => {
test('does not render anything', () => {
const searchClient = createSearchClient();

const { container } = render(
<InstantSearch indexName="indexName" searchClient={searchClient}>
<Configure hitsPerPage={666} />
</InstantSearch>
);

expect(container).toMatchInlineSnapshot(`<div />`);
});

test('sets search parameters', async () => {
const searchClient = createSearchClient();

act(() => {
render(
<InstantSearch indexName="indexName" searchClient={searchClient}>
<Configure hitsPerPage={666} />
</InstantSearch>
);
});

await waitFor(() => {
expect(searchClient.search).toHaveBeenCalledTimes(1);
expect(searchClient.search).toHaveBeenCalledWith([
{
indexName: 'indexName',
params: expect.objectContaining({
hitsPerPage: 666,
}),
},
]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render } from '@testing-library/react';
import React, { createRef } from 'react';

import { createSearchClient } from '../../../../../test/mock';
import { useConfigure } from '../../connectors/useConfigure';
import { Configure } from '../../components/Configure';
import { IndexContext } from '../../lib/IndexContext';
import { noop } from '../../lib/noop';
import { Index } from '../Index';
Expand All @@ -11,11 +11,6 @@ import { InstantSearchSSRProvider } from '../InstantSearchSSRProvider';

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

function Configure(props) {
useConfigure(props);
return null;
}

describe('Index', () => {
test('throws when used outside of <InstantSearch>', () => {
// Hide the errors from the test logs.
Expand Down
1 change: 1 addition & 0 deletions packages/react-instantsearch-hooks/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { default as version } from './version';
export * from './components/Configure';
export * from './components/DynamicWidgets';
export * from './components/Index';
export * from './components/InstantSearch';
Expand Down

0 comments on commit 3527b94

Please sign in to comment.