All Projects β†’ FezVrasta β†’ React Resize Aware

FezVrasta / React Resize Aware

Licence: mit
β‡²πŸ‘ A simple React Hook which allows to listen the resize event of any target element when it changes sizes

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Resize Aware

Class bot
An Automated Background Python bot that notifies you during your classes when your name is called or the keywords "present"/"attendance" are called out.
Stars: ✭ 36 (-91.51%)
Mutual labels:  listen
Fdsoundactivatedrecorder
Start recording when the user speaks
Stars: ✭ 227 (-46.46%)
Mutual labels:  listen
splitcloud-app
This is the repo for the legacy SplitCloud for iOS app built with ReactNative and a fork of StreamingKit project.
Stars: ✭ 59 (-86.08%)
Mutual labels:  listen
Play.cash
🎢 Music lovers, rejoice.
Stars: ✭ 89 (-79.01%)
Mutual labels:  listen
Zen Audio Player.github.io
Listen to YouTube videos, without the distracting visuals.
Stars: ✭ 180 (-57.55%)
Mutual labels:  listen
allas
LISTEN / NOTIFY connection pooler for PostgreSQL
Stars: ✭ 40 (-90.57%)
Mutual labels:  listen
Remit
RabbitMQ-backed microservices supporting RPC, pubsub, automatic service discovery and scaling with no code changes.
Stars: ✭ 24 (-94.34%)
Mutual labels:  listen
keeptune
Google Chrome Extension to download on Bandcamp, Soundcloud...
Stars: ✭ 49 (-88.44%)
Mutual labels:  listen
Progressmanager
⏳ Listen the progress of downloading and uploading in Okhttp, compatible Retrofit and Glide (δΈ€θ‘Œδ»£η ε³ε―η›‘ε¬ App δΈ­ζ‰€ζœ‰η½‘η»œι“ΎζŽ₯ηš„δΈŠδΌ δ»₯εŠδΈ‹θ½½θΏ›εΊ¦, εŒ…ζ‹¬ Glide ηš„ε›Ύη‰‡εŠ θ½½θΏ›εΊ¦).
Stars: ✭ 2,463 (+480.9%)
Mutual labels:  listen
pg-pubsub
Reliable PostgreSQL LISTEN/NOTIFY with inter-process lock support
Stars: ✭ 50 (-88.21%)
Mutual labels:  listen
Konamicode
Installs the Konami code easter-egg into your Android app ;)
Stars: ✭ 90 (-78.77%)
Mutual labels:  listen
Menutube
Catch YouTube into your macOS menu bar! πŸ¦„
Stars: ✭ 102 (-75.94%)
Mutual labels:  listen
uos
United Open-libraries of Sound. United procedures for open-source audio libraries. For FPC/Lazarus/fpGUI/MSEgui.
Stars: ✭ 112 (-73.58%)
Mutual labels:  listen
Easyble
Multi-devices process Bluetooth library for Android
Stars: ✭ 81 (-80.9%)
Mutual labels:  listen
browser-extension
Official LISTEN.moe browser extension
Stars: ✭ 23 (-94.58%)
Mutual labels:  listen
Tk Listen
A library that allows to listen network sockets with proper resource limits and error handling
Stars: ✭ 27 (-93.63%)
Mutual labels:  listen
vue-music-player
🎡 basic music player, keeps your favorite musics
Stars: ✭ 77 (-81.84%)
Mutual labels:  listen
Esp8266 Sniffer
An easy experiment which uses the ESP8266 wifi module to look for near smartphones around you
Stars: ✭ 410 (-3.3%)
Mutual labels:  listen
lplayer
lplayer is a simple audio player for simply listening
Stars: ✭ 40 (-90.57%)
Mutual labels:  listen
windows-app
Official LISTEN.moe Windows-only Client
Stars: ✭ 63 (-85.14%)
Mutual labels:  listen

react-resize-aware

It does one thing, it does it well: listens to resize events on any HTML element.

react-resize-aware is a zero dependency, ~600 bytes React Hook you can use to detect resize events without relying on intervals, loops, DOM manipulation detection or CSS redraws.

It takes advantage of the resize event on the HTMLObjectElement, works on any browser I know of, and it's super lightweight.

In addition, it doesn't directly alters the DOM, everything is handled by React.

Looking for the 2.0 docs? Click here

Installation

yarn add react-resize-aware

or with npm:

npm install --save react-resize-aware

Usage

The API is simple yet powerful, the useResizeAware Hook returns a React node you will place inside the measured element, and an object containing its sizes:

import React from 'react';
import useResizeAware from 'react-resize-aware';

const App = () => {
  const [resizeListener, sizes] = useResizeAware();

  return (
    <div style={{ position: 'relative' }}>
      {resizeListener}
      Your content here. (div sizes are {sizes.width} x {sizes.height})
    </div>
  );
};

Heads up!: Make sure to assign a position != initial to the HTMLElement you want to target (relative, absolute, or fixed will work).

API

The Hook returns an array with two elements inside:

[resizeListener, ...] (first element)

This is an invisible React node that must be placed as direct-child of the HTMLElement you want to listen the resize events of.

The node is not going to interfer with your layouts, I promise.

[..., sizes] (second element)

This object contains the width and height properties, these properties are going to be null before the component rendered, and will return a number after the component rendered.

Custom reporter

You can customize the properties of the sizes object by passing a custom reporter function as first argument of useResizeAware.

const customReporter = target => ({
  clientWidth: target != null ? target.clientWidth : null,
});

const [resizeListener, sizes] = useResizeAware(customReporter);

return (
  <div style={{ position: 'relative' }}>
    {resizeListener}
    Your content here. (div clientWidth is {sizes.clientWidth})
  </div>
);

The above example will report the clientWidth rather than the default offsetWidth and offsetHeight.

React to size variations

For completeness, below you can find an example to show how to make your code react to size variations using React Hooks:

const App = () => {
  const [resizeListener, sizes] = useResizeAware();
  
  React.useEffect(() => {
    console.log('Do something with the new size values');
  }, [sizes.width, sizes.height]);

  return (
    <div style={{ position: 'relative' }}>
      {resizeListener}
      Your content here.
    </div>
  );
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].