nkbt / react-debounce-input

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

Bug with minLength #159

Open sergio-ivanuzzo opened 1 month ago

sergio-ivanuzzo commented 1 month ago

Hi there !

I've found a bug and this is a small example to reproduce:

import React, {useState} from "react";
import {DebounceInput} from "react-debounce-input";

const MIN_LENGTH = 4;

const App = () => {
    const [text, setText] = useState("");
    return (
        <>
            <DebounceInput value={text} onChange={(e) => setText(e.target.value)} debounceTimeout={250} minLength={MIN_LENGTH} />
        </>
    )
};

export default App;

when input value length is MIN_LENGTH all is OK, but after I press backspace (so length become less than MIN_LENGTH) the whole input value removes.

sergio-ivanuzzo commented 1 month ago

Ok, I found this line: https://github.com/nkbt/react-debounce-input/blob/master/src/Component.js#L91, it was a bit unpredictable behavior, but now it is clear at least, what's going on. Probably it is possible to remove this behavior ?