How to use use-resize-observer - 2 common examples

To help you get started, we’ve selected a few use-resize-observer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dbismut / react-soft-slider / src / index.js View on Github external
style,
  slideStyle,
  enabled,
  trail,
  vertical,
  draggedScale,
  draggedSpring,
  trailingSpring,
  onDragStart,
  onDragEnd
}) {
  const slideStyleFunc = typeof slideStyle === 'function' ? slideStyle : () => slideStyle
  // root holds are slides wrapper node and we use a ResizeObserver
  // to observe its size in order to recompute the slides position
  // when it changes
  const [root, width, height] = useResizeObserver()

  const axis = vertical ? 'y' : 'x'
  const size = vertical ? height : width

  // indexRef is an internal reference to the current slide index
  const indexRef = useRef(index)

  // restPos holds a reference to the adjusted position of the slider
  // when rested
  const restPos = useRef(0)

  // visibleIndexes is a Set holding the index of slides that are
  // currently partially or fully visible (intersecting) in the
  // viewport
  const visibleIndexes = useRef(new Set())
  const firstVisibleIndex = useRef(0)
github cheeaun / busrouter-sg / assets / firstlast.js View on Github external
function FirstLastTimes() {
  const [stop, setStop] = useState('     ');
  const [stopName, setStopName] = useState(null);
  const [data, setData] = useState([]);

  const [tableRef, _, tableHeight] = useResizeObserver();
  const [timeLeft, setTimeLeft] = useState(null);
  const [timeStr, setTimeStr] = useState('');

  useEffect(() => {
    Promise.all([
      fetchCache(firstLastJSONPath, 24 * 60),
      fetchCache(stopsJSONPath, 24 * 60),
    ]).then(([flData, stopsData]) => {
      window.onhashchange = () => {
        const stop = location.hash.slice(1);
        const data = flData[stop];
        if (!data) {
          alert('Bus stop code not found.');
          return;
        }

use-resize-observer

A React hook that allows you to use a ResizeObserver to measure an element's size.

MIT
Latest version published 2 years ago

Package Health Score

73 / 100
Full package analysis

Popular use-resize-observer functions