react-throttle icon indicating copy to clipboard operation
react-throttle copied to clipboard

State and Props Lost

Open gpltaylor opened this issue 9 years ago • 9 comments

Due to wrapping Component, the state and props are not being passed down when used on an Element that's not a simple Input.

Example https://gist.github.com/gpltaylor/57756c5f0fdc5ee1fa4e7157c74275b2

The mouse event is called, Debounce only files are the right time, but the State is not updated as Debounce holds it's own state. However, the problem still happens when converting to props. The Elements XPos and YP{os are not updated and React Chrome debugging shows that the values are not passed into the Component Debounce. This library works for simple click events... it is designed for this type of wrapping?

gpltaylor avatar Sep 25 '16 09:09 gpltaylor

similar problem. state is not reaching the input that is wrapped by the debounce component. how can i make state update?

lhtdesignde avatar Oct 06 '16 09:10 lhtdesignde

Looking at the code, it does not appear to pass props down into the children. this would require a patch to fix this.

gpltaylor avatar Oct 06 '16 15:10 gpltaylor

Hey guys! Thanks for raising this issue. My apologies for the delay in replying. Could either of you post a use-case which fails, and I'll get started on a fix?

Thanks! :)

gmcquistin avatar Oct 07 '16 09:10 gmcquistin

great! my use case:

        <Debounce time='1500' handler='onKeyUp'>
          <input className='text' autoComplete='off' type='text'
                 disabled={this.state.showLoading}
                 onKeyUp={(event) => this.handleInputChange(event)} />
        </Debounce>

When I log this.state.showLoading just outside the debounce it's definetly coming through so ya debounce is not handing the state through. Thx for having a look!

lhtdesignde avatar Oct 07 '16 10:10 lhtdesignde

my Gist shows this in full. When moving the mouse over, the debounce works (thanx for that :)) however the state is not updated (passed down)

https://gist.github.com/gpltaylor/57756c5f0fdc5ee1fa4e7157c74275b2

gpltaylor avatar Oct 07 '16 15:10 gpltaylor

If you're pressed for time I might be able to look into this over the weekend.

gpltaylor avatar Oct 07 '16 15:10 gpltaylor

Is this still being worked on? I've encountered the exact same bug with my use-case.

Arthelon avatar Dec 07 '16 12:12 Arthelon

I am still working on this. I haven't had much time lately, but it will be fixed!

gmcquistin avatar Jan 13 '17 16:01 gmcquistin

Well, your code is cloning the React element, but it does so only once. Also it filters the props, leaving only the handlers. I could fix this by adding a call to componentWillReceiveProps and by using _.assing to compose the object props with the handlers. This is my fork. I will try to merge this now. All test are still passing, but I might be good to add a few more for this feature (I may try when have some time).

cristovao-trevisan avatar Mar 29 '17 17:03 cristovao-trevisan