0.0.7 • Published 1 year ago

react-use-resize v0.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

react-use-resize

Getting started

npm i react-use-resize
# or
yarn add react-use-resize

Examples

import useResize from 'react-use-resize';

function App() {
  const { elementRef } = useResize<HTMLHeadingElement>(() => {
    // ... onResize logic
  });

  return (
    <div>
      <h1 ref={elementRef}>Hello World</h1>
    </div>
  );
}

With checking element is overflowed

import useResize from 'react-use-resize';

function App() {
  const { elementRef, isWidthOverflowed, isHeightOverflowed } = useResize<HTMLHeadingElement>(
    () => {
      // ... onResize logic
    },
    {
      // Set enableOverflow to true!
      enableOverflow: true,
    },
  );

  return (
    <div>
      <h1 ref={elementRef}>Hello World</h1>
    </div>
  );
}

API Guides

Parameters

/**
 * Callback function when element is resize.
 */
export type OnResize = ResizeObserverCallback;

/**
 * Options for useResize hook
 */
export type Options = {
  /**
   * Options Resize Observer API  BOx options
   */
  box?: ResizeObserverBoxOptions;
  /**
   * Option for elements is overflowed.
   */
  enableOverflow?: boolean;
  /**
   * Delay for onResize callback function
   */
  debounceDelay?: number;
};

export type ElementSizeOverflow = {
  /**
   * Boolean for checking width is overflowed
   */
  width: boolean;
  /**
   * Boolean for checking height is overflowed
   */
  height: boolean;
};

Returns

type Returns<T extends Element> = {
  /**
   * Element is observed by ResizeObserver instance
   */
  elementRef: React.RefObject<T>;.

  /**
   * The value is for checking width of element is overflowed
   */
  isWidthOverflowed: boolean;

  /**
   * The value is for checking height of element is overflowed
   */
  isHeightOverflowed: boolean;
};

License

MIT

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago