Coder Social home page Coder Social logo

gautam-arora24 / resize-observer-hook Goto Github PK

View Code? Open in Web Editor NEW
45.0 1.0 6.0 5.19 MB

โš›๏ธ A React Hook to monitor changes in the size of an element using native ResizeObserver API ๐Ÿ”

Home Page: https://www.npmjs.com/package/resize-observer-hook

License: MIT License

JavaScript 43.05% HTML 41.32% CSS 15.63%
react resize-observer hook useeffect-hook hacktoberfest hacktoberfest2021

resize-observer-hook's Introduction

resize-observer-hook

All Contributors

A hook that uses Resize Observer API to monitor changes in the size of an element.

NPM JavaScript Style Guide

Install

npm install resize-observer-hook

Usage

import React from 'react'

import useResizeObserver from 'resize-observer-hook'

const App = () => {
  const [ref, width, height] = useResizeObserver()

  return (
    <div ref={ref}>
      {width} X {height}
    </div>
  )
}

You can add multiple ResizeObserverBoxOptions to the useResizeObserver like this ->

const [ref,width,height] = useResizeObserver("borderBoxSize");

ResizeObserverBoxOptions that are supported currently in the library ->

  • borderBoxSize
  • contentBoxSize
  • contentRect

Note โš ๏ธ - Some options aren't supported in some broswers so if you provide any option that is not being supported in your current browser, it will automatically use contentRect to calculate height and width of the observed element.

See more details over here -> https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry

Contributing

You can help this library to grow by contributing here. Pick any issue or open one. Let us know what you are working on and ask your questions in the issues itself :)

The package is made up of 2 main folders:

  • /src contains all the resize-observer-hook code
  • /example is our create-react-app based demo website

To setup and run a local copy:

  1. Clone this repo with https://github.com/Gautam-Arora24/resize-observer-hook.git
  2. Run npm install in the root folder
  3. Run npm install in the example folder
  4. In seperate terminal window, run npm start in the root.
  5. In seperate terminal window, run npm start in the example folder.

When you're done working on your changes, submit a PR with the details and include a screenshot if you've changed anything visually.

License

MIT ยฉ Gautam-Arora24, and the contributors.

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


Gautam Arora

๐Ÿ’ป

mehan

๐ŸŽจ

Nikhil Maske

๐Ÿ’ป

Batman09

๐Ÿ“–

Keshav

๐Ÿ“–

gim

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

resize-observer-hook's People

Contributors

allcontributors[bot] avatar gautam-arora24 avatar gimhol avatar keshavgbpecdelhi avatar mehanalavimajd avatar morewings avatar nikhilmaske-2001 avatar sarthakvaishnav09 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

resize-observer-hook's Issues

Migrate to Typescript.

Future Plans
Plans to add typing support to the library whenever I will get some time.

Add a CONTRIBUTION.md file.

Currently, we lack on documentation on how the beginners should start contributing to the library. We should add a CONTRIBUTION.md file that will contain all the information required by the beginners to start contributing.

The key points on the documentation/file will include -

  • Development environment required before contributing.
  • Git principles that should be followed while contributing to the library.
  • The code style.
  • How to claim an issue?
  • How to make a successful Pull Request?

Need a logo for the library.

We need some sort of logo for the library. So, if you are a Graphic designer and wanted to contribute to the open source community then here's your good chance.

Remove the import of `useRef` from usage section in README.md.

The piece of code in the usage section contains the import of useRef which is no longer needed. The need for the ref parameter for the hook was removed in #2.

Changes Needed

โ€ข Remove the useRef import from the example code.
โ€ข Remove the ref paramater from the hook in the README.md.

Features support that can be added.

Discussed in #17

Originally posted by Gautam-Arora24 September 25, 2021
I just wanna know from the community members that what new features can be added to the library's scope?

Make the hook self dependent by removing the ref parameter.

Currently, the useResizeObserver hook is dependent on the ref parameter which it will get from the element it is going to observe.

What changes can be made?

We can remove the ref parameter from the code and make it self-dependent by adding the useRef hook inside the hook itself. The ref parameter will be returned from the hook now.

Refractor

There are some files that are empty and some code that is generated by npx create-react-app xyz which is useless. We can remove this part for better and clean code.

Add a CONTRIBUTING.md file.

Currently, we lack documentation on how beginners should start contributing to the library. We should add a CONTRIBUTING.md file that will contain all the information required by the beginners to start contributing.

The key points on the documentation/file will include -

  • Development environment required before contributing.
  • Git principles that should be followed while contributing to the library.
  • The code style.
  • How to claim an issue?
  • How to make a successful Pull Request?

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.