Giter VIP home page Giter VIP logo

react-use-resize's Introduction

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

react-use-resize's People

Contributors

mugglim avatar

Stargazers

Roman avatar  avatar Harry avatar

Watchers

 avatar

react-use-resize's Issues

Fix onReize function is not excuted!

fix onReize event is not fired!

Description

To develop(check list)

  • onResize function will be excuted after element is resized!

To know

  • v0.0.2 is worked for me.

Setup dev environment(lint, git hook)

Setup dev environment

Description

  • 일관성있는 개발 환경을 구축하기 위한 도구를 설치한다.

To develop(check list)

  • husky (for using git hook)
  • lint-staged(will be triggered pre commit)
  • commitlint(will be triggered pre commit)

To know

  • None

Add examples directory for demo

Add examples directory for demo

Description

  • please add example directory for demo

To develop(check list)

  • add examples for demo

To know

  • None..

Add debounceDelay option

Add debounceDelay option

Description

To develop(check list)

  • add debounce delay for optimizing callback function call
const { elementRef } = useResize<HTMLHeadingElement>({
    onResize: () => {
      // ...
    },
    options: {
      // default `debounceDelay` is 0
      debounceDelay : 1_000
    }
  });

To know

  • None..

Change parameter types

Change parameter types

Description

  • Change parameter order and types for DX.

To develop(check list)

  • change useResize parameters
// AS-IS
const useResize = <T extends Element>({
  onResize,
  options = {
   // ...
  },
}: UseResizeProps) => {}

// TO-BE
const useResize = <T extends Element>(
  onResize: OnResize,
  options: Options = {
    // ...
  },
) => {}

## To know

- `onResize` parameter is first parameter
- `options` parameter is second parameter

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.