Created
March 25, 2024 13:42
-
-
Save ChristianAlexander/6cd5d51d9ff66ff236b328118ee1de9a to your computer and use it in GitHub Desktop.
Fuse Result Highlight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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