react-instantsearch icon indicating copy to clipboard operation
react-instantsearch copied to clipboard

Feature Request: Provide loading and error props for react native hits connectors.

Open ylac opened this issue 9 years ago • 4 comments

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.

ylac avatar May 11 '17 10:05 ylac

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

mthuret avatar May 11 '17 11:05 mthuret

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?

ylac avatar May 11 '17 13:05 ylac

I'm not sure to get why you'll need that information present inside the hits connector?

You got several possibilities here:

  1. 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>;
 });
  1. 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>;
 });
  1. 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?

mthuret avatar May 11 '17 13:05 mthuret

Ok I got it to work like possibility 2. Thanks for your help.

ylac avatar May 12 '17 00:05 ylac