Feature Request: Provide loading and error props for react native hits connectors.
Do you want to request a feature or report a bug?
Feature
Feature: What is your use case for such a feature?
Require loading/error info for React Native app.
Feature: What is your proposed API entry? The new option to add? What is the behavior?
Could you please add the loading (currently under searchResults.searching) and error variables as provided props for all the Hits connectors (connectHits, connectHitsPerPage and connectInfiniteHits)? They are very useful in slow/unreliable internet situations.
What is the version you are using? Always use the latest one before opening a bug issue.
3.3.1.
Hi @ylac,
Those variables are accessible through our createConnector api. See: https://community.algolia.com/react-instantsearch/guide/Conditional_display.html
You can use this method to build your own <Loading/>, <Error/> etc, component.
However, we're thinking to provide an intermediary api to do that, that will not require any usage of createConnector.
Let me know if this help
Thanks for your reply. I was more looking to use the connectInfiniteHits connectors but with loading/error props. Is there an easy way to do that without copying the whole connectInfiniteHits connector?
I'm not sure to get why you'll need that information present inside the hits connector?
You got several possibilities here:
- Conditional rendering of component
const content = createConnector({
displayName: 'ConditionalError',
getProvidedProps(props, searchState, searchResults) {
return {error: searchResults.error};
},
})(({error}) => {
const content = error
? <div>An error occurred: {error.message}</div>
: <div>Some results</div>;
return <div>{content}</div>;
});
- pass the error to another component to do the conditional rendering inside it
const content = createConnector({
displayName: 'ConditionalError',
getProvidedProps(props, searchState, searchResults) {
return {error: searchResults.error};
},
})(({error}) => {
return <div><InfiniteHits error={error}</div>;
});
- build your own
<Loading/>, <Error/>widgets (based on the create connector) to do something more declarative like:
<InstantSearch>
<Error/>
<InfiniteHits/>
</InstantSearch>
Will one of those work for you? If not, can you detail why and how your app is design?
Ok I got it to work like possibility 2. Thanks for your help.