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

Commit 322adfd

Browse files
authored
docs(hooks): make sure example runs without ts errors (#3207)
* docs(hooks): make sure example runs without ts errors I don't understand why ci wasn't red before now, but in https://app.circleci.com/pipelines/github/algolia/react-instantsearch/1614/workflows/de241179-b866-4dc6-b576-0a4de456f2fb/jobs/47848 it is * easier * pick
1 parent b347061 commit 322adfd

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

examples/hooks/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ function Hit({ hit }: HitProps) {
3434
<span
3535
className="Hit-label"
3636
dangerouslySetInnerHTML={{
37-
__html: (hit._highlightResult as any).name.value,
37+
__html:
38+
hit._highlightResult && hit._highlightResult.name
39+
? hit._highlightResult.name.value
40+
: '',
3841
}}
3942
/>
4043
<span className="Hit-price">${hit.price}</span>

examples/hooks/components/Hits.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@ import { useHits, UseHitsProps } from 'react-instantsearch-hooks';
44

55
import { cx } from '../cx';
66

7-
export type HitsProps = React.ComponentProps<'div'> &
7+
export type HitsProps<THit> = React.ComponentProps<'div'> &
88
UseHitsProps & {
9-
hitComponent: <THit extends AlgoliaHit<Record<string, unknown>>>(props: {
10-
hit: THit;
11-
}) => JSX.Element;
9+
hitComponent: (props: { hit: THit }) => JSX.Element;
1210
};
1311

14-
export function Hits({ hitComponent: Hit, ...props }: HitsProps) {
12+
export function Hits<THit extends AlgoliaHit<Record<string, unknown>>>({
13+
hitComponent: Hit,
14+
...props
15+
}: HitsProps<THit>) {
1516
const { hits } = useHits(props);
1617

1718
return (
1819
<div className={cx('ais-Hits', props.className)}>
1920
<ol className="ais-Hits-list">
2021
{hits.map((hit) => (
2122
<li key={hit.objectID} className="ais-Hits-item">
22-
<Hit hit={hit} />
23+
<Hit hit={hit as unknown as THit} />
2324
</li>
2425
))}
2526
</ol>

examples/hooks/components/RefinementList.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import {
33
useRefinementList,
44
UseRefinementListProps,
55
} from 'react-instantsearch-hooks';
6+
import { RefinementListWidgetParams } from 'instantsearch.js/es/widgets/refinement-list/refinement-list';
67

78
import { ControlledSearchBox } from './ControlledSearchBox';
89
import { cx } from '../cx';
910

1011
export type RefinementListProps = React.ComponentProps<'div'> &
11-
UseRefinementListProps;
12+
UseRefinementListProps &
13+
Pick<RefinementListWidgetParams, 'searchable' | 'searchablePlaceholder'>;
1214

1315
export function RefinementList(props: RefinementListProps) {
1416
const {
@@ -81,7 +83,7 @@ export function RefinementList(props: RefinementListProps) {
8183
/>
8284
<span
8385
className="ais-RefinementList-labelText"
84-
dangerouslySetInnerHTML={{ __html: item.highlighted }}
86+
dangerouslySetInnerHTML={{ __html: item.highlighted! }}
8587
/>
8688
<span className="ais-RefinementList-count">{item.count}</span>
8789
</label>

examples/hooks/components/SearchBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ControlledSearchBox } from './ControlledSearchBox';
55

66
export type SearchBoxProps = React.ComponentProps<'div'> & UseSearchBoxProps;
77

8-
export function SearchBox(props?: SearchBoxProps) {
8+
export function SearchBox(props: SearchBoxProps) {
99
const { query, refine, isSearchStalled } = useSearchBox(props);
1010
const [value, setValue] = useState(query);
1111
const inputRef = useRef<HTMLInputElement>(null);

0 commit comments

Comments
 (0)