flexdinesh / react-socks

🎉 React library to render components only on specific viewports 🔥
MIT License
426 stars 29 forks source link

Consider throttling the window resize event #3

Closed wuz closed 5 years ago

wuz commented 6 years ago

React already throttles calls to setState, which is the only thing in the resize function currently - however it might be more clear/worthwhile in the future to throttle this function:

  componentDidMount() {
    window.addEventListener('resize', () => {
      this.setState({
        width: BreakpointUtil.currentWidth,
        currentBreakpoint: BreakpointUtil.currentBreakpointName
      });
    });
}

Cool library! Definitely look forward to trying it out on a project!

flexdinesh commented 6 years ago

@wuz We definitely need this. Feel free to create a PR if you this mind mapped already.

flexdinesh commented 5 years ago

PR #9 adds code to throttle resize event.