How to highlight matches within a string with JSX?

后端 未结 2 1988
情歌与酒
情歌与酒 2021-01-14 21:06

I have a custom autocomplete, so when you type, it will display a list of suggestions based on the input value. In the list, I would like to bold the characters that are th

2条回答
  •  清酒与你
    2021-01-14 21:31

    You just append your mapper as children inside your auto complete component.

    
      
      { matches.map(function(match, idx){ let re = new RegExp(value, 'g'); let str = match.replace(re, ''+ value +''); return (
    • {str}
    • ) }) }

提交回复
热议问题