Skip to content

Commit 994089f

Browse files
authored
Improve with-algolia-react-instantsearch example and convert to TypeScript (vercel#42617)
Converted to TypeScript to match Contribution docs, and updated/simplified the example. - Replaced stylesheets in Head component with imported styles - Removed `style-loader`, `css-loader`, `cross-env`, `prop-types` packages - Removed custom webpack config ## Documentation / Examples - [X] Make sure the linting passes by running `pnpm build && pnpm lint` - [X] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
1 parent 081b8fb commit 994089f

File tree

14 files changed

+202
-236
lines changed

14 files changed

+202
-236
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import {
2+
RefinementList,
3+
SearchBox,
4+
Hits,
5+
Configure,
6+
Highlight,
7+
Pagination,
8+
InstantSearch,
9+
} from 'react-instantsearch-dom'
10+
import type { InstantSearchProps } from 'react-instantsearch-dom'
11+
12+
const HitComponent = ({ hit }: any) => (
13+
<div className="hit">
14+
<div>
15+
<div className="hit-picture">
16+
<img src={`${hit.image}`} />
17+
</div>
18+
</div>
19+
<div className="hit-content">
20+
<div>
21+
<Highlight attribute="name" hit={hit} />
22+
<span> - ${hit.price}</span>
23+
<span> - {hit.rating} stars</span>
24+
</div>
25+
<div className="hit-type">
26+
<Highlight attribute="type" hit={hit} />
27+
</div>
28+
<div className="hit-description">
29+
<Highlight attribute="description" hit={hit} />
30+
</div>
31+
</div>
32+
</div>
33+
)
34+
35+
export function Search(props: InstantSearchProps) {
36+
return (
37+
<InstantSearch {...props}>
38+
<Configure hitsPerPage={12} />
39+
<header>
40+
<h1>React InstantSearch + Next.js</h1>
41+
<SearchBox />
42+
</header>
43+
<main>
44+
<div className="menu">
45+
<RefinementList attribute="categories" />
46+
</div>
47+
<div className="results">
48+
<Hits hitComponent={HitComponent} />
49+
</div>
50+
</main>
51+
<footer>
52+
<Pagination />
53+
</footer>
54+
</InstantSearch>
55+
)
56+
}

examples/with-algolia-react-instantsearch/components/app.js

-81
This file was deleted.

examples/with-algolia-react-instantsearch/components/head.js

-48
This file was deleted.

examples/with-algolia-react-instantsearch/components/index.js

-3
This file was deleted.

examples/with-algolia-react-instantsearch/components/instantsearch.js

-13
This file was deleted.

examples/with-algolia-react-instantsearch/next.config.js

-17
This file was deleted.

examples/with-algolia-react-instantsearch/package.json

+14-8
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
"private": true,
33
"scripts": {
44
"dev": "next",
5-
"build": "cross-env NODE_ENV=development next build",
5+
"build": "next build",
66
"start": "next start"
77
},
88
"dependencies": {
9-
"algoliasearch": "4.3.0",
10-
"cross-env": "^7.0.2",
11-
"css-loader": "1.0.0",
9+
"algoliasearch": "^4.14.2",
10+
"instantsearch.css": "^7.4.5",
1211
"next": "latest",
13-
"prop-types": "^15.5.10",
14-
"qs": "^6.4.0",
12+
"qs": "^6.11.0",
1513
"react": "^18.2.0",
1614
"react-dom": "^18.2.0",
17-
"react-instantsearch-dom": "6.6.0",
18-
"style-loader": "^0.17.0"
15+
"react-instantsearch-dom": "^6.38.0"
16+
},
17+
"devDependencies": {
18+
"@types/node": "^18.11.9",
19+
"@types/qs": "^6.9.7",
20+
"@types/react": "^18.0.25",
21+
"@types/react-dom": "^18.0.8",
22+
"@types/react-instantsearch-core": "^6.26.2",
23+
"@types/react-instantsearch-dom": "^6.12.3",
24+
"typescript": "^4.8.4"
1925
}
2026
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { AppProps } from 'next/app'
2+
import 'instantsearch.css/themes/algolia.css'
3+
import '../styles/global.css'
4+
5+
export default function MyApp({ Component, pageProps }: AppProps) {
6+
return <Component {...pageProps} />
7+
}

examples/with-algolia-react-instantsearch/pages/index.js

-60
This file was deleted.

0 commit comments

Comments
 (0)