Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debounceTimeout -1 not working #90

Closed
opami opened this issue Dec 4, 2017 · 3 comments · Fixed by #117
Closed

debounceTimeout -1 not working #90

opami opened this issue Dec 4, 2017 · 3 comments · Fixed by #117
Assignees

Comments

@opami
Copy link

opami commented Dec 4, 2017

Hi,

I have a problem with setting debounceTimeout prop to -1 and not getting any onChange event triggered even when pressing the enter key. react-debounce-input version is 3.1.0

Below is example code to reproduce the issue. Am I missing some props that should be passed along for the debounceTimeout -1 to work?

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


  class App extends Component {
    render() {
      return (
          <DebounceInput value={""} onChange={e => console.log("onChange() called")} 
            debounceTimeout={-1}/>
      )
    }
  }
  export default App;

By quickly debugging the code it seems that in the forceNotify function the execution always returns on the first if statement where it checks the this.isDebouncing value

  forceNotify = event => {
    if (!this.isDebouncing) {
      return;
    }

  if (this.cancel) {
    this.cancel();
  }

  const {value} = this.state;
  const {minLength} = this.props;

  if (value.length >= minLength) {
    this.doNotify(event);
  } else {
    this.doNotify({...event, target: {...event.target, value}});
  }
  };
@Dartv
Copy link

Dartv commented Feb 22, 2018

@opami I have the same problem. How did you solve it? One hack I can think of is to use debounceTimeout={Infinity}. Are there any drawbacks?

@opami
Copy link
Author

opami commented Mar 5, 2018

@Dartv I used the same workaround you are suggesting so just setting debounceTimeout to a large enough value

@MatejBransky
Copy link

MatejBransky commented May 7, 2018

I've just did this:

if (!this.isDebouncing && this.props.timeout >= 0) { // << just extend the condition with timeout
  return;
}

if (this.cancel) {
  this.cancel();
}

const {value} = this.state;
const {minLength} = this.props;

if (value.length >= minLength) {
  this.doNotify(event);
} else {
  this.doNotify({...event, target: {...event.target, value}});
}

@nkbt nkbt self-assigned this Oct 17, 2019
@nkbt nkbt closed this as completed in #117 Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants