Hello,
I am having a problem with the Customize the UI - connectHighlight.
My problem is that I have an object with products. I filtered those products based on tags. It is working fine, the problem is that those tags have prefixes. Example: Colour_. So in my front end I want to display the products without the prefixes. It is working fine as you can see in the first picture. My problem is that it does not work for the Highlighted item when I make a search. Example second picture.
.The third picture is a solution I somehow managed to make it work. However it is still finding the prefix.
Hope that it is not too confusing. Is there a way to manipulate the value that I am receiving with he Highlight ?
my code looks like this:
import { connectHighlight } from 'react-instantsearch-dom'
const CustomHighlight = ({ highlight, attribute, hit }) => {
const transformString = str => {
return str.split('_').pop()
}
const parsedHit = highlight({
highlightProperty: '_highlightResult',
attribute,
hit,
})
return (
<span>
{parsedHit.map((part, index) =>
part.isHighlighted ? (
<mark key={index} className="highlight-mark">
{transformString(part.value)}
</mark>
) : (
<span key={index}>{transformString(part.value)}</span>
)
)}
</span>
)
}
export default connectHighlight(CustomHighlight)