Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(highlight): switch to index as key (#2690)
Browse files Browse the repository at this point in the history
the reason is that the full value could be duplicate, so we added the index; but the index can't be duplicate within the list.
  • Loading branch information
Haroenv authored and samouss committed Jul 29, 2019
1 parent a544231 commit 51de682
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 57 deletions.
10 changes: 3 additions & 7 deletions packages/react-instantsearch-dom/src/components/Highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

function generateKey(i, value) {
return `split-${i}-${value}`;
}

export const Highlight = ({
cx,
value,
Expand Down Expand Up @@ -49,11 +45,11 @@ const Highlighter = ({
if (Array.isArray(item)) {
const isLast = i === parsedHighlightedValue.length - 1;
return (
<span key={generateKey(i, hit[attribute][i])}>
<span key={i}>
{item.map((element, index) => (
<Highlight
cx={cx}
key={generateKey(index, element.value)}
key={index}
value={element.value}
highlightedTagName={tagName}
nonHighlightedTagName={nonHighlightedTagName}
Expand All @@ -68,7 +64,7 @@ const Highlighter = ({
return (
<Highlight
cx={cx}
key={generateKey(i, item.value)}
key={i}
value={item.value}
highlightedTagName={tagName}
nonHighlightedTagName={nonHighlightedTagName}
Expand Down
Loading

0 comments on commit 51de682

Please sign in to comment.