I am new to react js. I was supposed to achieve the following in my project:
- Find a defined string in a large string
- Make the defined link clickable if it is found in the large string
My code:
function FindWord() {
const givenWord = "hello there click this Forgot password if you do not remember your password"
const toSearch="Forgot password"
return (
<>
{givenWord.includes(toSearch)?
givenWord.substring(0,givenWord.indexOf(toSearch).toString()) + `<span style={{color:'red'}}>${toSearch}</span>` + (toSearch)
:"No"}
</>
)
}
Is there a better approach?