React-instantsearch: Can't highlight an array

Created on 12 Oct 2019  路  2Comments  路  Source: algolia/react-instantsearch

This works:

{hits.map(item => (
  <ul>
    {item.tags.map((value, index) => (
      <li key={value}>{value}</li>
    ))}
  </ul>
))}

But when I try to highlight:

{hits.map(item => (
  <ul>
    {item.tags.map((value, index) => (
      <li key={value}><Highlight hit={item} attribute={item.tags[index]} /></li>
    ))}
  </ul>
))}

Doesn't work. Am I doing this wrong?

Most helpful comment

The attribute is a string, not a value, so this would be more like the following:

https://codesandbox.io/s/react-instantsearch-app-e5v38

{item.tags.map((_cat, i) => (
 <li key={i}><Highlight attribute={`tags[${i}]`} hit={item} /></li>
))}

Hope that helps!

All 2 comments

The attribute is a string, not a value, so this would be more like the following:

https://codesandbox.io/s/react-instantsearch-app-e5v38

{item.tags.map((_cat, i) => (
 <li key={i}><Highlight attribute={`tags[${i}]`} hit={item} /></li>
))}

Hope that helps!

@Haroenv Thanks!

Was this page helpful?
0 / 5 - 0 ratings