renatorib / react-sizes

:left_right_arrow: Hoc to easily map window sizes to props.
722 stars 36 forks source link

Bug: throttle can't be configured due to an error in the code #27

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi,

great library. I was playing around with it and found a bug. You use lodash.throttle to slow down how often react rerenders when the browser changes. You made it "possible" to configure this value using the SizesProvider component. This however does not work. Because the logic is expecting this value on this.context.throttle. The SizesProvider however stores it in a dict with the key _ReactSizesConfig_.

The line ~57 in withSizes.js should be

throttledDispatchSizes = throttle(
      this.dispatchSizes,
      (this.context[contextKey] || {}).throttle || 200
    )

and not:

throttledDispatchSizes = throttle(
     this.dispatchSizes,
     this.context.throttle || 200
)
renatorib commented 6 years ago

Thanks!

ghost commented 6 years ago

Great thanks for publishing.