Skip to content

Instantly share code, notes, and snippets.

@ChristianAlexander
Created March 25, 2024 13:42
Show Gist options
  • Save ChristianAlexander/6cd5d51d9ff66ff236b328118ee1de9a to your computer and use it in GitHub Desktop.
Save ChristianAlexander/6cd5d51d9ff66ff236b328118ee1de9a to your computer and use it in GitHub Desktop.
Fuse Result Highlight
function formatMatch({ indices, value }) {
let lastIndex = 0;
return (
<span>
{indices.map(([start, end], index) => {
const nonMatch = value.slice(lastIndex, start);
lastIndex = end;
const match = value.slice(start, end);
return (
<React.Fragment key={index}>
{nonMatch}
<b>{match}</b>
</React.Fragment>
);
})}
{value.slice(lastIndex)}
</span>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment