nkbt / react-debounce-input

React component that renders Input with debounced onChange
MIT License
450 stars 61 forks source link

External validation misrender #154

Open andybenedict opened 2 years ago

andybenedict commented 2 years ago

In reference to issue #130

It was the check we discussed, but not for the reason I thought.

Since migrating from componentWillReceiveProps to componentDidUpdate the initial state update on the first keypress is being processed before the isDebouncing flag is set.

Previously, the debouncing flag was getting set before the render occurred, but now it is happening earlier, so I expect you were experiencing difficulty and stuttered renders.

In order to combat hitting a check that the isDebouncing flag was intended to avoid, an additional check was added that causes the undesirable rendering behavior.

To mitigate, I set it up to conditionally set the isDebouncing flag (if denouncing is necessary when calling this.notify) before we set the initial state.

As far as I can tell, all of the current examples appear to work perfectly and skipping that extra render appears to slightly improve performance as well. (Though I'm no expert in profiling react apps πŸ˜€). I also added another example to demonstrate using the input in the context of external validation that can correct the value.