Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as React from 'react';
  2. import { throttle } from 'core/utils';
  3.  
  4. const defaultWidth = 984;
  5. const mediumWidth = 800;
  6. const breakPoint = 1250;
  7.  
  8. export const withResize = Component => props => {
  9.   const pageSize = window.innerWidth > breakPoint ? defaultWidth : mediumWidth;
  10.   const [width, setChartWidth] = React.useState(pageSize);
  11.  
  12.   React.useEffect(() => {
  13.     window.addEventListener('resize', updateWidth);
  14.     return () => {
  15.       window.removeEventListener('resize', updateWidth);
  16.     };
  17.   });
  18.  
  19.   const updateWidth = throttle(() => {
  20.     window.innerWidth <= breakPoint ? setChartWidth(mediumWidth) : setChartWidth(defaultWidth);
  21.   });
  22.  
  23.   return <Component width={width} {...props} />;
  24. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement