Adding additional data to Hit component

Hi

I’m currently using algolia react for a dating matching system. I’d like to pass some extra information into the Hits component but it seems to be stripping any other props, is this possible?

eg ‘’

Thanks for any help.

Joe

Hi @joe,

I assume that you want to do something of this props. In that case the best way is to use this connectHits connector.

See here for the connector guide: https://community.algolia.com/react-instantsearch/guide/Connectors.html

Usage:

const CustomHits = connectHits(({hits, data}) => {
        return ... // hits rendering
});

<CustomHits data="test" />

Ah OK that’s great thanks. Would it be possible to pass in a class to the connect component?

Thanks again for your help.

Joe

Yes you can pass a React.Component class and use it inside the connector :slight_smile:

Hi

Thanks again! I know this might be a stupid question but the Hits component gives me the ‘Hit’. When using the connector do I have to manually loop through the Hits object or should I have access to the individual hit somewhere?

Thanks

Joe

The connectHits give you an items prop that contain all the hits. Then it’s up to you to iterate on it and build your hit rendering :slight_smile:

You can see here a usage example: https://github.com/algolia/react-instantsearch/blob/master/docgen/src/examples/e-commerce/App.js

1 Like

Thanks so much for your help