Download react-instantsearch/examples/hooks-react-native/src/InfiniteHits.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-instantsearch/examples/hooks-react-native/src/InfiniteHits.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-instantsearch/examples/hooks-react-native/src/InfiniteHits.tsx
-
curl -L -o InfiniteHits.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-instantsearch/examples/hooks-react-native/src/InfiniteHits.tsx
1.55 kB
| import React, { forwardRef } from 'react'; | |
| import { StyleSheet, View, FlatList } from 'react-native'; | |
| import { Hit as AlgoliaHit } from '@algolia/client-search'; | |
| import { | |
| useInfiniteHits, | |
| UseInfiniteHitsProps, | |
| } from 'react-instantsearch-hooks'; | |
| type InfiniteHitsProps<THit> = UseInfiniteHitsProps & { | |
| hitComponent: (props: { hit: THit }) => JSX.Element; | |
| }; | |
| export const InfiniteHits = forwardRef( | |
| <THit extends AlgoliaHit<Record<string, unknown>>>( | |
| { hitComponent: Hit, ...props }: InfiniteHitsProps<THit>, | |
| ref: React.ForwardedRef<FlatList<THit>> | |
| ) => { | |
| const { hits, isLastPage, showMore } = useInfiniteHits(props); | |
| return ( | |
| <FlatList | |
| ref={ref} | |
| data={hits as unknown as THit[]} | |
| keyExtractor={(item) => item.objectID} | |
| ItemSeparatorComponent={() => <View style={styles.separator} />} | |
| onEndReached={() => { | |
| if (!isLastPage) { | |
| showMore(); | |
| } | |
| }} | |
| renderItem={({ item }) => ( | |
| <View style={styles.item}> | |
| <Hit hit={item as unknown as THit} /> | |
| </View> | |
| )} | |
| /> | |
| ); | |
| } | |
| ); | |
| const styles = StyleSheet.create({ | |
| separator: { | |
| borderBottomWidth: 1, | |
| borderColor: '#ddd', | |
| }, | |
| item: { | |
| padding: 18, | |
| }, | |
| }); | |
| declare module 'react' { | |
| // eslint-disable-next-line no-shadow | |
| function forwardRef<TRef, TProps = unknown>( | |
| render: (props: TProps, ref: React.Ref<TRef>) => React.ReactElement | null | |
| ): (props: TProps & React.RefAttributes<TRef>) => React.ReactElement | null; | |
| } | |