2

I have a textarea component that has an onChange attribute.

I want to make some function that will console log the textarea value when the user stops typing in the textarea. One idea I had would be to make a function that saves after 1 second of waiting, but the timer restarts when it is called.

So like this:

function save() {
    // wait for one second (this resets if save() is called again)
    // console.log(textarea.value)
}

How could I do something like this?

  • 1
    What you're asking for is a `debounce` method. Libraries like lodash, underscore have one. – dwjohnston Oct 12 '20 at 05:16
  • @dwjohnston I will give it a shot - very new to react though so it is a bit hard to understand at first glance. –  Oct 12 '20 at 05:18

0 Answers0