Skip to content

Commit 71710ff

Browse files
authored
feat(React InstantSearch Native Hooks): add Getting Started example (#358)
1 parent 9708021 commit 71710ff

File tree

18 files changed

+12272
-0
lines changed

18 files changed

+12272
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true,
3+
"40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true
4+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
node_modules/
2+
.expo/
3+
dist/
4+
npm-debug.*
5+
*.jks
6+
*.p8
7+
*.p12
8+
*.key
9+
*.mobileprovision
10+
*.orig.*
11+
web-build/
12+
13+
# macOS
14+
.DS_Store
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import React, { useRef, useState } from 'react';
2+
import { FlatList, SafeAreaView, StyleSheet, Text, View } from 'react-native';
3+
import { StatusBar } from 'expo-status-bar';
4+
import algoliasearch from 'algoliasearch/lite';
5+
import { InstantSearch } from 'react-instantsearch-hooks';
6+
7+
import { InfiniteHits } from './src/InfiniteHits';
8+
import { SearchBox } from './src/SearchBox';
9+
import { Highlight } from './src/Highlight';
10+
import { Filters } from './src/Filters';
11+
import { ProductHit } from './types/ProductHit';
12+
13+
const searchClient = algoliasearch(
14+
'latency',
15+
'6be0576ff61c053d5f9a3225e2a90f76'
16+
);
17+
18+
export default function App() {
19+
const [isModalOpen, setModalOpen] = useState(false);
20+
const listRef = useRef<FlatList>(null);
21+
22+
function scrollToTop() {
23+
listRef.current?.scrollToOffset({ animated: false, offset: 0 });
24+
}
25+
26+
return (
27+
<SafeAreaView style={styles.safe}>
28+
<StatusBar style="light" />
29+
<View style={styles.container}>
30+
<InstantSearch searchClient={searchClient} indexName="instant_search">
31+
<SearchBox onChange={scrollToTop} />
32+
<Filters
33+
isModalOpen={isModalOpen}
34+
onToggleModal={() => setModalOpen((isOpen) => !isOpen)}
35+
onChange={scrollToTop}
36+
/>
37+
<InfiniteHits ref={listRef} hitComponent={Hit} />
38+
</InstantSearch>
39+
</View>
40+
</SafeAreaView>
41+
);
42+
}
43+
44+
type HitProps = {
45+
hit: ProductHit;
46+
};
47+
48+
function Hit({ hit }: HitProps) {
49+
return (
50+
<Text>
51+
<Highlight hit={hit} attribute="name" />
52+
</Text>
53+
);
54+
}
55+
56+
const styles = StyleSheet.create({
57+
safe: {
58+
flex: 1,
59+
backgroundColor: '#252b33',
60+
},
61+
container: {
62+
flex: 1,
63+
backgroundColor: '#ffffff',
64+
flexDirection: 'column',
65+
},
66+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# ais-ecommerce-demo-app
2+
3+
_This project was generated with [create-instantsearch-app](https://github.com/algolia/create-instantsearch-app) by [Algolia](https://algolia.com)._
4+
5+
## Get started
6+
7+
To run this project locally, install the dependencies and run the local server:
8+
9+
```sh
10+
npm install
11+
npm start
12+
```
13+
14+
Alternatively, you may use [Yarn](https://http://yarnpkg.com/):
15+
16+
```sh
17+
yarn
18+
yarn start
19+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"expo": {
3+
"name": "ais-ecommerce-demo-app",
4+
"slug": "ais-ecommerce-demo-app",
5+
"version": "1.0.0",
6+
"orientation": "portrait",
7+
"icon": "./assets/icon.png",
8+
"splash": {
9+
"image": "./assets/splash.png",
10+
"resizeMode": "contain",
11+
"backgroundColor": "#ffffff"
12+
},
13+
"updates": {
14+
"fallbackToCacheTimeout": 0
15+
},
16+
"assetBundlePatterns": ["**/*"],
17+
"ios": {
18+
"supportsTablet": true
19+
},
20+
"android": {
21+
"adaptiveIcon": {
22+
"foregroundImage": "./assets/adaptive-icon.png",
23+
"backgroundColor": "#FFFFFF"
24+
}
25+
},
26+
"web": {
27+
"favicon": "./assets/favicon.png"
28+
}
29+
}
30+
}
17.1 KB
Loading
1.43 KB
Loading
21.9 KB
Loading
46.2 KB
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = function (api) {
2+
api.cache(true);
3+
return {
4+
presets: ['babel-preset-expo'],
5+
};
6+
};

0 commit comments

Comments
 (0)