0

I have a working demo of this InstantSearch, but I can't find the way of displaying the results as a grid and not a list.

 <InstantSearch
                appId="xxxxx"
                apiKey="xxxxxx"
                indexName="xxxx"
            >
            <SearchBox />
            <div>
              <Hits hitComponent={Product} />
            </div>
   </InstantSearch>

And Product is a card with the result information. The only way I seem to be able to access the list of results is with Hits, but that won't allow me to create a grid.

Any help is welcome.

bobylito
  • 3,172
  • 22
  • 27
Roberto
  • 1,793
  • 1
  • 18
  • 19

2 Answers2

2

You can use the connectHits connector to use your very own markup.

Connectors are Higher Order Components.

Here's a little example:

const Hits = connectHits(({hits}) => {
    const items = hits.map(hit => <div>{hit.name}</div>);
    return <Grid><items></Grid>
});

More information about connectors here: https://community.algolia.com/react-instantsearch/guide/Connectors.html

Marie
  • 366
  • 2
  • 6
2

Thanks to @Marie

This is how I've done it and it works.

import React from 'react';

//Import Components
import {connectHits} from 'react-instantsearch/connectors';
import Product from './Product'

const MyHits = (props)  => {
    const items = props.hits.map(hit => <Product hit={hit} />);
    return (
        <div>
            <div className="my-grid mdc-layout-grid">
                <div className="mdc-layout-grid__inner">
                    {items}
                </div>
            </div>
        </div>
    );
}


export default connectHits(MyHits);
Haroen Viaene
  • 1,329
  • 18
  • 33
Roberto
  • 1,793
  • 1
  • 18
  • 19