This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hooks): introduce
useConfigure
(#3181)
- Loading branch information
1 parent
18297f8
commit aa2eb9b
Showing
6 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { useConfigure, UseConfigureProps } from 'react-instantsearch-hooks'; | ||
|
||
export type ConfigureProps = UseConfigureProps; | ||
|
||
export function Configure(props: ConfigureProps) { | ||
useConfigure(props); | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './Configure'; | ||
export * from './Hits'; | ||
export * from './RefinementList'; | ||
export * from './SearchBox'; |
28 changes: 28 additions & 0 deletions
28
packages/react-instantsearch-hooks/src/__tests__/useConfigure.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
|
||
import { createInstantSearchTestWrapper } from '../../../../test/utils'; | ||
import { useConfigure } from '../useConfigure'; | ||
|
||
describe('useConfigure', () => { | ||
test('returns the connector render state', async () => { | ||
const wrapper = createInstantSearchTestWrapper(); | ||
const { result, waitForNextUpdate } = renderHook( | ||
() => useConfigure({ hitsPerPage: 40 }), | ||
{ | ||
wrapper, | ||
} | ||
); | ||
|
||
// Initial render state from manual `getWidgetRenderState` | ||
expect(result.current).toEqual({ | ||
refine: expect.any(Function), | ||
}); | ||
|
||
await waitForNextUpdate(); | ||
|
||
// InstantSearch.js state from the `render` lifecycle step | ||
expect(result.current).toEqual({ | ||
refine: expect.any(Function), | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import connectConfigure from 'instantsearch.js/es/connectors/configure/connectConfigure'; | ||
|
||
import { useConnector } from './useConnector'; | ||
|
||
import type { | ||
ConfigureConnectorParams, | ||
ConfigureWidgetDescription, | ||
} from 'instantsearch.js/es/connectors/configure/connectConfigure'; | ||
|
||
export type UseConfigureProps = ConfigureConnectorParams['searchParameters']; | ||
|
||
export function useConfigure(props: UseConfigureProps) { | ||
return useConnector<ConfigureConnectorParams, ConfigureWidgetDescription>( | ||
connectConfigure, | ||
{ searchParameters: props } | ||
); | ||
} |