Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-listen-resize

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-listen-resize

Listening resize can use hooks、HOC、normal function.

  • 0.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

react-listen-resize

NPM Version Build Status Coverage Status

Listener resize

Install

yarn

yarn add react-listen-resize

npm

npm install --save react-listen-resize

UMD

<script src="https://unpkg.com/react-listen-resize@0.1.0/dist/index.umd.js"></script>

OR

<script src="https://unpkg.com/react-listen-resize@0.1.0/dist/index.umd.min.js"></script>

Tips: You can find the library on window.ReactListenResize.

Import

ES2015

import { useListenResize, createListenResize, createWithListenResize } from 'react-listen-resize'

CommonJS

const {
  useListenResize,
  createListenResize,
  createWithListenResize
} = require('react-listen-resize')

Usage

createListenResize(callback, isInitExcutionCallback)

createListenResize is a normal function.

import { createListenResize } from 'react-listen-resize'

const [state, cancelListenResize] = createListenResize(
  ({ eventResize, state: { innerHeight, innerWidth } }) => {
    console.log('eventResize-callback:: ', eventResize)
    console.log('state-callback:: ', innerHeight, innerWidth)
  },
  true
)
Params

createListenResize can pass two Params.

PropertyDescriptionTypeDefaultisRequired
callbacklisten for resize trigger callback.({eventResize, state: {innerHeight, innerWidth}}) => voidundefinedfalse
isInitExcutionCallbackWhether to excute the initial callback.booleanfalsefalse

createListenResize returns an array.

PropertyDescriptionType
array[0] - stateReturn {innerHeight, innerWidth}object
array[1] - cancelListenResizeCall to cancel listening for resizefunction

useListenResize(callback, isInitExcutionCallback)

useListenResize is a custom hook.

import { useListenResize } from 'react-listen-resize'

function Example() {
  const [state, cancelListenResize] = useListenResize(
    ({ eventResize, state: { innerHeight, innerWidth } }) => {
      console.log('eventResize-callback:: ', eventResize)
      console.log('state-callback:: ', innerHeight, innerWidth)
    },
    true
  )
}
Params

useListenResize can pass two Params.

PropertyDescriptionTypeDefaultisRequired
callbacklisten for resize trigger callback.({eventResize, state: {innerHeight, innerWidth}}) => voidundefinedfalse
isInitExcutionCallbackWhether to excute the initial callback.booleanfalsefalse

useListenResize returns an array.

PropertyDescriptionType
array[0] - stateReturn {innerHeight, innerWidth} .object
array[1] - cancelListenResizeCall to cancel listening for resize.function

createWithListenResize()

createWithListenResize is a HOC.

import { createWithListenResize } from 'react-listen-resize'

function Example(props) {
  const { innerHeight, innerWidth, cancelListenResize } = props
}

Example = createWithListenResize()(Example)
Params

createWithListenResize return values in props.

PropertyDescriptionType
innerHeightinnerHeightnumber
innerWidthinnerWidthnumber
cancelListenResizeCall to cancel listening for resize.function

LICENSE

MIT License

Keywords

FAQs

Package last updated on 11 Jun 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc