Answer the question
In order to leave comments, you need to log in
Implementing found value highlighting in React?
Hello everyone, there is a moment that I do not know how to solve.
filteredMessages - a filtered array with objects that match the search.
const filteredMessages = useMemo(() => {
if (history) {
return history.filter(item => item.text.toLocaleLowerCase().includes(findText?.toLowerCase().trim()));
}
return null;
}, [findText, history]);
<ul>
{filteredMessages.map(message => (
<li key={message.text + Math.random()}>
<span>{message.text}</span>
</li>
))}
</ul>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question