Skip to content

Instantly share code, notes, and snippets.

@vvo

vvo/Nested.js Secret

Last active October 26, 2016 09:51
Show Gist options
  • Save vvo/771d86353bdc5908e6e720fb512dea29 to your computer and use it in GitHub Desktop.
Save vvo/771d86353bdc5908e6e720fb512dea29 to your computer and use it in GitHub Desktop.
Example of doing multiple indices search using react-instantsearch
import {
InstantSearch,
SearchBox as OriginalSearchBox,
Hits
} from 'react-instantsearch';
import createConnector from 'react-instantsearch/src/core/createConnector.js';
const UseParentQuery = OriginalSearchBox.connect(() => null);
const Nested = createConnector({
displayName: 'Nested',
getProps: (props, state) => ({
parentState: state,
}),
})(props => {
return <InstantSearch
appId="latency"
apiKey="6be0576ff61c053d5f9a3225e2a90f76"
indexName="ikea"
state={props.parentState}
onStateChange={() => {}}
createURL={() => {}}
>
<div>
<UseParentQuery/>
<Hits/>
</div>
</InstantSearch>;
});
// then you can nest <Nested/> anywhere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment