question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

After selecting item on Typeahead, onChange callback triggered twice.

See original GitHub issue

Version

2.4.0

Steps to reproduce

Add Typeahead component which looks like this

<Typeahead
  onChange={(selected) => {
    this.setState({selected});
  }}
  options={['one', 'two']}
  selected={this.state.selected}
/>

Breakpoint inside on onChange Select any item

Expected Behavior

onChange callback hitted once

Actual Behavior

onChange callback hitted twice

Notes

It looks like first call is comming from typeaheadInputContainer.js. Whenever user selects item, _handleChange for Input got executed, which triggers this.props.onChange(...). Second call is comming from typeaheadContainer.js because selected prop is updated, which triggers componentWillReceiveProps(...) -> this._updateText(...) -> this.props.onInputChange(...) -> this.props.onChange()

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
vudodovcommented, Mar 1, 2018

I’m agree with @coolkev on his last comment in #305

onChange events should really not be raised in the componentWillReceiveProps event

1reaction
ericgiocommented, Feb 26, 2018

Thanks for the report. Sounds like the behavior described in #305. It’s the expected behavior as written, but is unexpected compared to how typical form elements work. Seems like I need to rethink a bit how and where onChange and onInputChange are being called.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Type Ahead Text Control logs onChange Event twice if ...
I'm using Type Ahead Text Control from IBM BPM UI toolkit ; I notice it logs onChange Event twice if an item is...
Read more >
react-bootstrap-typeahead How do I trigger a callback (update ...
When finished selecting, he can press Enter to push his selections into an array in the state. The input will then clear and...
Read more >
jQuery | Autocomplete Selection Event - GeeksforGeeks
The autocomplete select action is triggered when the user selects one of the options from the pre-populated list.
Read more >
Fire OnChange only once - Telerik UI for Blazor
I observe twice firing onchange event in dropdownlist or other inputs. I want the event to fire only once when the user selects...
Read more >
How to Use Browser Event Listeners in React for Search and ...
js app that I put together just to get up and running with an example of search with autocomplete using The Star Wars...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found