In my react component, I'm using the replace method to replace a word however this doesn't appear to be working:
const myComponent = () => {
const [textVal, setTextVal] = useState("hello there")
textVal.replace("hello", "hi")
console.log(textVal) // expecting "hi there" but still getting "hello there"
return ( ... )
}
replacereturns a new string, it doesn't modify the old. Second, if you want this to persist between renders, you would need to callsetTextValwith the new value.