Ad

Concatenate Text From React Hook

- 1 answer

I have following hook:

const [textToFront, setTextToFront] = useState('');

When I call setTextToFront I see that old state was cleared, I want to implement simple thing, I just want to create one big String in the hook and display. How to store and add new coming state to old state?

Ad

Answer

Try

setTextToFront(`${textToFront}${newAppendedText}`);
Ad
source: stackoverflow.com
Ad