New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

react-hooks-utilities

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hooks-utilities

Just some react hooks utils... (WIP)

latest
Source
npmnpm
Version
1.0.11
Version published
Weekly downloads
13
1200%
Maintainers
1
Weekly downloads
 
Created
Source

Just some react hooks utils... More coming soon (WIP).

Install

npm install --save react-hooks-utilities

Usage

useStateWithCb:

import React from 'react'
import { useStateWithCb } from 'react-hooks-utilities'

function testCallback(value) {
    const el = document.getElementById('test')
    el.innerText = `Current value is ${value}`
}

function Example() {
    const [state, setState] = useStateWithCb(0, testCallback)
    const increment = () => setState((prev) => prev + 1)
    const decrement = () => setState((prev) => prev - 1)
    return (
        <div>
            <button onClick={increment}>Increment</button>
            <button onClick={decrement}>Decrement</button>
            <p id="test"/>
        </div>
    )
}

useDimensions:

import React from 'react'
import { useDimensions } from 'react-hooks-utilities'

function Example() {
    const {
        ref,
        height,
        width
    } = useDimensions()
    return (
        <div ref={ref}>
            <p>Width: {width}px</p>
            <p>Height: {height}px</p>
        </div>
    )
}

useWindowDimensions:

import React from 'react'
import { useWindowDimensions } from 'react-hooks-utilities'

function Example() {
    const {
        height,
        width,
        breakpoint
    } = useWindowDimensions()
    return (
        <div>
            <p>Width: {width}px</p>
            <p>Height: {height}px</p>
            <p>Current breakpoint: {breakpoint}</p>
        </div>
    )
}

useMouseCoordinates:

import React from 'react'
import { useMouseCoordinates } from 'react-hooks-utilities'

function Example() {
    const {
        x,
        y
    } = useMouseCoordinates()
    return (
        <div>
            <p>{x}px</p>
            <p>{y}px</p>
        </div>
    )
}

Or visit this link for live examples.

Todo

  • Move to TypeScript.
  • Write tests.
  • Update examples page.
  • More hooks :sunny:

License

MIT © johnnyboi91

Keywords

react

FAQs

Package last updated on 08 Feb 2021

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