DefinitelyTyped/types/react-instantsearch-native/react-instantsearch-native-tests.tsx
Haroen Viaene 4c9daf7346
[react-instantsearch] update to v6 (#43111)
* [react-instantsearch] update to v6

- createIndex & createInstantSearch no longer exist, replaced by the component in -core
- InstantSearch no longer accepts appId & apiKey
- InstantSearch no longer accepts `root` (& neither Index, but that wasn't typed)
- /server API has changed, now exposes directly `findResultsState`

* fix small typo things

* update native tests

* declare newer stuff

* prevent error

* interfaces are required apparently

* Update types/react-instantsearch-core/index.d.ts

* Update types/react-instantsearch-dom/index.d.ts

* fix lint?

* remove failing test

* hmm

* hmm this test is weird but that's ok

* old typescript
2020-03-23 11:30:33 -04:00

71 lines
1.8 KiB
TypeScript

import * as React from "react";
import { SearchBox, Hits } from "react-instantsearch-dom";
import { InstantSearch, Index, connectStateResults } from 'react-instantsearch-native';
import { values } from 'lodash';
// https://community.algolia.com/react-instantsearch/guide/Conditional_display.html
const App2 = () => (
<InstantSearch searchClient={{}} indexName="first">
<SearchBox />
<AllResults>
<div>
<Index indexName="first">
<IndexResults>
<div>
<div>first: </div>
<Hits />
</div>
</IndexResults>
</Index>
<Index indexName="second">
<IndexResults>
<div>
<div>second: </div>
<Hits />
</div>
</IndexResults>
</Index>
<Index indexName="third">
<IndexResults>
<div>
<div>third: </div>
<Hits />
</div>
</IndexResults>
</Index>
</div>
</AllResults>
</InstantSearch>
);
const IndexResults = connectStateResults(
({ searchState, searchResults, children }) =>
searchResults && searchResults.nbHits !== 0 ? (
children as React.ReactElement
) : (
<div>
No results has been found for {searchState.query} and index{' '}
{searchResults ? searchResults.index : ''}
</div>
)
);
const AllResults = connectStateResults(({ allSearchResults, children }) => {
const hasResults =
allSearchResults &&
values(allSearchResults).some(results => results.nbHits > 0);
return !hasResults ? (
<div>
<div>No results in category, products or brand</div>
<Index indexName="first" />
<Index indexName="second" />
<Index indexName="third" />
</div>
) : (
children as React.ReactElement
);
});