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
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 committed Jul 19, 2019
1 parent a544231 commit b9dab96
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

0 comments on commit b9dab96

Please sign in to comment.