chenglou / react-chosen

React wrapper for Chosen jQuery.
96 stars 25 forks source link

Events not firing if using `setState` on event #7

Open jeffchan opened 10 years ago

jeffchan commented 10 years ago

I am using a slightly modified version to detect when the Chosen dropdown has closed (chosen:hiding_dropdown event). When I select an option from the dropdown, Chosen fires two events, "chosen:hiding_dropdown" and "change." However, in React, only one event shows up.

You can see the reproduction here http://jsfiddle.net/jeffchan/vySpj/

Steps to reproduce:

  1. Select an option from the dropdown
  2. Check the console output.

Expected: show dropdown hide dropdown handle change

Actual: show dropdown hide dropdown

original: https://groups.google.com/d/msgid/reactjs/cd78a2fb-2c6d-406c-b0b4-1ec8ce869308%40googlegroups.com?utm_medium=email&utm_source=footer

chenglou commented 10 years ago

(Cross-posted from google groups)

I just checked it and I think it's because you did a setState after the events fired. If you remove the setState, it works fine. Messing with the combination of jquery events, chosen's hacky dom manipulations and react's setState is not fun at all.

I wish we have an acceptable react-only chosen substitute now. Oh well.

(Will solve it if I have the time)