Socket
Socket
Sign inDemoInstall

@rescui/use-resize-observer

Package Overview
Dependencies
2
Maintainers
3
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @rescui/use-resize-observer

ResizeObserver hook


Version published
Weekly downloads
1.8K
decreased by-11.68%
Maintainers
3
Install size
2.58 MB
Created
Weekly downloads
 

Readme

Source

ResizeObserver hook

This package is used for observing react elements. It uses ResizeObserver and alleviates some of its bugs.

It's best used together with React refs. It can be used with raw HTML elements, although it's better to avoid that.

Usage examples

React ref example

import React, { useRef } from 'react';
import { useResizeObserver } from '@rescui/use-resize-observer';

const MyComponent = () => {
  const ref = useRef<HTMLElement>(null);
  useResizeObserver(ref, (entry: ResizeObserverEntry) => {
    // resize logic
  });

  return <div ref={ref}>To the moon!</div>;
};

HTML element example

Note: Avoid this option when possible due to additional re-renders when using callback refs and useState. Use React ref instead.

import React, { useState } from 'react';
import { useResizeObserver } from '@rescui/use-resize-observer';

const MyComponent = () => {
  const [el, setEl] = useState<HTMLElement>(null);
  useResizeObserver(el, (entry: ResizeObserverEntry) => {
    // resize logic
  });

  return <div ref={setEl}>To the moon!</div>;
};

FAQs

Last updated on 13 Sep 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc