Skip to content

React hook library, ready to use, written in Typescript.

License

Notifications You must be signed in to change notification settings

refeals/usehooks-ts

Β 
Β 

Repository files navigation

usehooks-ts banner


usehooks-ts

React hook library, ready to use, written in Typescript.

Contributor Covenant NPM Downloads NPM Downloads License npm bundle size npm All Contributors


npm i usehooks-ts

Created by Julien Caron and maintained with ❀️ by an amazing team of developers.

πŸ’« Introduction

useHooks(πŸ”₯).ts is a React hooks library, written in Typescript and easy to use. It provides a set of hooks that enables you to build your React applications faster. The hooks are built upon the principles of DRY (Don't Repeat Yourself). There are hooks for most common use cases you might need.

The library is designed to be as minimal as possible. It is fully tree-shakable (using the ESM version), meaning that you only import the hooks you need, and the rest will be removed from your bundle making the cost of using this library negligible. Most hooks are extensively tested and are being used in production environments.

Usage example

import { useLocalStorage } from 'usehooks-ts'

function Component() {
  const [value, setValue] = useLocalStorage('my-localStorage-key', 0)

  // ...
}

πŸͺ Available Hooks

  • useBoolean β€” handles boolean state with useful utility functions.
  • useClickAnyWhere β€” handles click events anywhere on the document.
  • useCopyToClipboard β€” copies text to the clipboard.
  • useCountdown β€” manages countdown.
  • useCounter β€” manages a counter with increment, decrement, reset, and setCount functionalities.
  • useDarkMode β€” returns the current state of the dark mode.
  • useDebounceCallback β€” creates a debounced version of a callback function.
  • useDebounceValue β€” returns a debounced version of the provided value, along with a function to update it.
  • useDocumentTitle β€” sets the document title.
  • useEventCallback β€” creates a memoized event callback.
  • useEventListener β€” attaches event listeners to DOM elements, the window, or media query lists.
  • useHover β€” tracks whether a DOM element is being hovered over.
  • useIntersectionObserver β€” tracks the intersection of a DOM element with its containing element or the viewport.
  • useInterval β€” creates an interval that invokes a callback function at a specified delay.
  • useIsClient β€” determines if the code is running on the client side (in the browser).
  • useIsMounted β€” determines if the component is currently mounted.
  • useIsomorphicLayoutEffect β€” uses either
  • useLocalStorage β€” uses local storage to persist state across page reloads.
  • useMap β€” manages a key-value map state with setter actions.
  • useMediaQuery β€” tracks the state of a media query.
  • useOnClickOutside β€” handles clicks outside a specified element.
  • useReadLocalStorage β€” reads a value from local storage, closely related to useLocalStorage().
  • useResizeObserver β€” observes the size of an element using the ResizeObserver API.
  • useScreen β€” tracks the screen dimensions and properties.
  • useScript β€” dynamically loads scripts and tracking their loading status.
  • useScrollLock β€” A custom hook that locks and unlocks scroll.
  • useSessionStorage β€” uses session storage to persist state across page reloads.
  • useStep β€” manages and navigates between steps in a multi-step process.
  • useTernaryDarkMode β€” manages ternary (system, dark, light) dark mode with local storage support.
  • useTimeout β€” handles timeouts in React components.
  • useToggle β€” manages a boolean toggle state in React components.
  • useUnmount β€” runs a cleanup function when the component is unmounted.
  • useWindowSize β€” tracks the size of the window.

πŸ’š Backers

Big thanks go to all our backers! [Become a backer]

Sentry
Sentry
KATT
KATT
Adhi Ravishankar
Adhi Ravishankar
great-work-told-is
great-work-told-is

✨ Contributors

Big thanks go to all our contributors! [Become a contributor]

Julien
Julien

πŸ–‹ πŸ’» 🎨 πŸ€”
a777med
a777med

πŸ’»
Nguyen Tien Dat
Nguyen Tien Dat

πŸ’»
Elias Cohenca
Elias Cohenca

πŸ–‹
JoΓ£o Deroldo
JoΓ£o Deroldo

πŸ› πŸ’»
Nishit
Nishit

πŸ’»
Jon Koops
Jon Koops

πŸ’»
LoneRifle
LoneRifle

πŸ’»
Viktor
Viktor

πŸ€” πŸ›
Bruno Clermont
Bruno Clermont

πŸ’¬
yoannesbourg
yoannesbourg

πŸ€”
Strange2x
Strange2x

πŸ€”
Jason Pickens
Jason Pickens

πŸ›
Sel-Vin Kuik
Sel-Vin Kuik

πŸ›
isaac
isaac

πŸ›
Bruno RZN
Bruno RZN

πŸ’» πŸ‘€
Nathan Manceaux-Panot
Nathan Manceaux-Panot

πŸ’» πŸ‘€
Dien Vu
Dien Vu

πŸ€”
Oleg Kusov
Oleg Kusov

πŸ€”
Matthew Guy
Matthew Guy

πŸ€”
andrewbihl
andrewbihl

πŸ›
lancepollard
lancepollard

πŸ›
Mukul Bansal
Mukul Bansal

πŸ›
Jean-Luc Mongrain sur la Brosse
Jean-Luc Mongrain sur la Brosse

πŸ’» πŸ€”
Nic
Nic

πŸ–‹
Dan Wood
Dan Wood

πŸ’»
jo wendenbuerger
jo wendenbuerger

πŸ›
Andrew Nosenko
Andrew Nosenko

πŸ›
CharlieJhonSmith
CharlieJhonSmith

πŸ’»
Sullivan SENECHAL
Sullivan SENECHAL

πŸ€” πŸ›
Jason Long
Jason Long

πŸ›
kxm766
kxm766

πŸ›
Quentin
Quentin

πŸ’» πŸ€” πŸ–‹
Daniel Lazar
Daniel Lazar

πŸ’» πŸ›
Mark Terrel
Mark Terrel

πŸ› πŸ’»
Andreas Herd
Andreas Herd

πŸ›
Sonjoy Datta
Sonjoy Datta

πŸ’»
Ilya Belsky
Ilya Belsky

πŸ›
James Barrett
James Barrett

πŸ’»
AbbalYouness
AbbalYouness

πŸ’»
didriklind
didriklind

πŸ’» ⚠️
hexp1989
hexp1989

πŸ’»
Alvaro Serrano
Alvaro Serrano

πŸ–‹
Egehan DΓΌlger
Egehan DΓΌlger

πŸ’»
PabloLION
PabloLION

πŸ› πŸ’»
David Sanchez
David Sanchez

πŸ›
Ajay Raja
Ajay Raja

πŸ›
Andy Merskin
Andy Merskin

πŸ€”
Avirup Ghosh
Avirup Ghosh

πŸ’» πŸ›
Sanne WintrΓ©n
Sanne WintrΓ©n

πŸ›
Alessandro
Alessandro

πŸ›
Andrey Tatarenko
Andrey Tatarenko

πŸ›
Anton Rusak
Anton Rusak

πŸ›
Mahmood Bagheri
Mahmood Bagheri

πŸ’»
Anver Sadutt
Anver Sadutt

πŸ–‹
Bogdan Ailincai
Bogdan Ailincai

πŸ’»
Simeon Griggs
Simeon Griggs

πŸ›
Kepro
Kepro

πŸ›
Jake Lippert
Jake Lippert

πŸ›
Tu Nguyen Anh
Tu Nguyen Anh

πŸ› πŸ’»
Luke Shiels
Luke Shiels

πŸ›
Sergei Kolyago
Sergei Kolyago

πŸ€”
Adham Akmal Azmi
Adham Akmal Azmi

πŸ›
Alek Kowalczyk
Alek Kowalczyk

πŸ›
Sean Callahan
Sean Callahan

πŸ›
Joshua Bean
Joshua Bean

πŸ’» πŸ›
Tim Zhao
Tim Zhao

πŸ›
Patrick
Patrick

πŸ›
Bryce Dorn
Bryce Dorn

πŸ’»
angusd3v
angusd3v

πŸ’»
Davide Di Simone
Davide Di Simone

πŸ›
Jack Herrington
Jack Herrington

πŸ›
Avi Sharvit
Avi Sharvit

πŸ’» πŸ›
Nicolae Maties
Nicolae Maties

πŸ›
Shardul Aeer
Shardul Aeer

πŸ›
Herlon Aguiar
Herlon Aguiar

πŸ›
Alexis Oney
Alexis Oney

πŸ–‹
curtvict
curtvict

πŸ’»
JosuΓ© Cortina
JosuΓ© Cortina

πŸ–‹
Alex / KATT
Alex / KATT

πŸ’»
Mourad EL CADI
Mourad EL CADI

πŸ’» πŸ›
James Hulena
James Hulena

πŸ›
Matthew Hailwood
Matthew Hailwood

πŸ’» πŸ‘€
Michael Norrie
Michael Norrie

πŸ›
Valentin Politov
Valentin Politov

πŸ’»
Marnus Weststrate
Marnus Weststrate

πŸ’»
mancuoj
mancuoj

πŸ–‹
Chat Sumlin
Chat Sumlin

πŸ’»
Owen Haupt
Owen Haupt

πŸ› πŸ–‹
ubarbaxor
ubarbaxor

πŸ’»
Michael Mior
Michael Mior

πŸ› πŸ–‹
Pierre
Pierre

πŸ’»
Harry B
Harry B

πŸ›
Valerie
Valerie

πŸ› πŸ’»
Steven Vachon
Steven Vachon

πŸ’»
Sean Kirby
Sean Kirby

⚠️ πŸ’»
Alecsander Farias
Alecsander Farias

πŸ’»
Rahul Mishra
Rahul Mishra

πŸ’» πŸ‘€ πŸ–‹
Bryant Smith
Bryant Smith

πŸ’» πŸ›
Rob Hannay
Rob Hannay

πŸ’»
Hooriza
Hooriza

πŸ’» πŸ›
ShanSenanayake
ShanSenanayake

πŸ’»
Philip Ghering
Philip Ghering

πŸ’»
Ladislas Dellinger
Ladislas Dellinger

πŸ’»
Haff
Haff

πŸ’»
Lisandro
Lisandro

πŸ’»
Amir hossein rezaei
Amir hossein rezaei

πŸ’»
Nicolas Macian
Nicolas Macian

πŸ› πŸ’»
Nate Forsyth
Nate Forsyth

πŸ’»
satelllte
satelllte

πŸ’» πŸ›
Federico Panico
Federico Panico

πŸ’»
William Pei Yuan
William Pei Yuan

πŸ’»
Mihai
Mihai

πŸ’» πŸ›
Habib Ogunsola
Habib Ogunsola

πŸ–‹
Ash Furrow
Ash Furrow

πŸ’»
Daniel TuruΘ™
Daniel TuruΘ™

πŸ’»
Rahul Chaudhary
Rahul Chaudhary

πŸ–‹ πŸ›
Joshua Ojoawo
Joshua Ojoawo

πŸ€” πŸ›
Jack
Jack

πŸ’»
Jon Linkens
Jon Linkens

πŸ’» πŸ›
Jeongjin Oh
Jeongjin Oh

πŸ›
Tianning Li
Tianning Li

πŸ’»
Lars Artmann
Lars Artmann

πŸ–‹
KBobovskiy
KBobovskiy

πŸ’»
✨ Kathryn Gonzalez ✨
✨ Kathryn Gonzalez ✨

πŸ–‹
Yaroslav Chapelskyi
Yaroslav Chapelskyi

πŸ–‹
Samuel Van Erps
Samuel Van Erps

πŸ‘€
ojolowoblue
ojolowoblue

πŸ–‹
Andrii Kostenko
Andrii Kostenko

πŸ’»
Akeem Allen
Akeem Allen

πŸ’» πŸ›
trongbinhnguyen
trongbinhnguyen

πŸ–‹
Aniruddha Sil
Aniruddha Sil

πŸ’»
λ°•μ°¬ν˜
λ°•μ°¬ν˜

πŸ‘€
Anish
Anish

πŸ’»
Hugo Hutri
Hugo Hutri

πŸ–‹
Balz Guenat
Balz Guenat

πŸ’»
OtterGeorge
OtterGeorge

πŸ’»
Samay Sagar
Samay Sagar

πŸ–‹
Pedro Lisboa
Pedro Lisboa

πŸ›
Henrique Malheiros
Henrique Malheiros

πŸ›
Kevin Newman
Kevin Newman

πŸ’»
a503189
a503189

πŸ–‹
Mourad EL CADI
Mourad EL CADI

πŸ’»
Pedro Henrique Lopes
Pedro Henrique Lopes

πŸ’»
Danbi Lee
Danbi Lee

πŸ’»
Connor Jennings
Connor Jennings

πŸ’»
Lucas Gomes
Lucas Gomes

πŸ› πŸ’»
Martin Zagora
Martin Zagora

πŸ’»
KvD
KvD

πŸ’»
Alex
Alex

πŸ’»
Kacey Cleveland
Kacey Cleveland

πŸ‘€
Avirup Ghosh
Avirup Ghosh

πŸ›
yabbal
yabbal

πŸ’»
Craig Patik
Craig Patik

πŸ›
Soldeplata Saketos Candela
Soldeplata Saketos Candela

πŸ’»
TENDOUZHI
TENDOUZHI

πŸ›
Marcin Wachulski
Marcin Wachulski

πŸ›
Salman Fazal
Salman Fazal

πŸ›
shrugs
shrugs

πŸ›
hyodori
hyodori

πŸ›
Eleazar β€œE” Ramos
Eleazar β€œE” Ramos

πŸ›
retnag
retnag

πŸ›
J young Lee
J young Lee

πŸ›
Filip Weiss
Filip Weiss

πŸ›
Marius Gundersen
Marius Gundersen

πŸ›
Syed Aman Ali
Syed Aman Ali

πŸ›
Axel Ingadi
Axel Ingadi

πŸ›
AndyP
AndyP

πŸ›
ishanVaghasiya
ishanVaghasiya

πŸ›
Nico Martinucci
Nico Martinucci

πŸ›
Shiv Bhonde | shivbhonde.eth
Shiv Bhonde | shivbhonde.eth

πŸ›
fritzmonkey
fritzmonkey

πŸ›
Rodrigo Mesquita
Rodrigo Mesquita

πŸ›
Moshe Simantov
Moshe Simantov

πŸ›
Beka
Beka

πŸ›
Abdallah Alkaser
Abdallah Alkaser

πŸ› πŸ’»
Carl Smith
Carl Smith

πŸ›
Orlando Groppo
Orlando Groppo

πŸ›
MartΔ³n Saly
MartΔ³n Saly

πŸ›
Quinn Shanahan
Quinn Shanahan

πŸ›
Antoine Kingue
Antoine Kingue

πŸ›
Ε½an Ε½lender
Ε½an Ε½lender

πŸ›
Sebastian Dominguez
Sebastian Dominguez

πŸ›
James Cowan
James Cowan

πŸ›
Bayram Ali Basgul
Bayram Ali Basgul

πŸ›
Wyatt Castaneda
Wyatt Castaneda

πŸ›
Tim Neville
Tim Neville

πŸ›
Thomas Pigarelli
Thomas Pigarelli

πŸ›
James Herdman
James Herdman

πŸ›
Grzegorz Pociejewski
Grzegorz Pociejewski

πŸ›
RenΓ© Verheij
RenΓ© Verheij

πŸ›
PatrykKuniczak
PatrykKuniczak

πŸ›
Paolo BoΕΎac
Paolo BoΕΎac

πŸ›
Rein
Rein

πŸ›
FloorianB
FloorianB

πŸ›
Xuan Hung
Xuan Hung

πŸ›
Monawwar Abdullah
Monawwar Abdullah

πŸ›
Haroldo de Oliveira Pinheiro
Haroldo de Oliveira Pinheiro

πŸ›
Tamjid Ahmed
Tamjid Ahmed

πŸ›
jv-lopez
jv-lopez

πŸ›
Callum Macrae
Callum Macrae

πŸ›
bywater529
bywater529

πŸ›
Kevin He
Kevin He

πŸ›
FredericoGauz
FredericoGauz

πŸ›
Jonathan "JonLem" Lemos
Jonathan "JonLem" Lemos

πŸ›
Xegulon
Xegulon

πŸ›
Tom Smedley
Tom Smedley

πŸ›
lightbluepoppy
lightbluepoppy

πŸ›
Derek Oware
Derek Oware

πŸ›
Lance Gliser
Lance Gliser

πŸ›
J. Lewis
J. Lewis

πŸ›
Yair
Yair

πŸ›
Nishchit
Nishchit

πŸ›
Devofy
Devofy

πŸ›
Josh Guyette
Josh Guyette

πŸ›
Dora Li
Dora Li

πŸ›
Kristian Gerardsson
Kristian Gerardsson

πŸ›
James Powell
James Powell

πŸ›
Boaz Poolman
Boaz Poolman

πŸ›
roker15
roker15

πŸ›
Fadhil Ahmad
Fadhil Ahmad

πŸ›
Chandler-Zhu
Chandler-Zhu

πŸ›
Nghi Nguyen
Nghi Nguyen

πŸ›
Shravan Sunder
Shravan Sunder

πŸ›
Johannes5
Johannes5

πŸ›
sebahhpeya
sebahhpeya

πŸ›
Or Nakash
Or Nakash

πŸ›
Erez Makavy
Erez Makavy

πŸ›
Andy Merskin
Andy Merskin

πŸ›
ChainAlert Bot
ChainAlert Bot

πŸ›
Taylor Morgan
Taylor Morgan

πŸ›
wisdomabioye
wisdomabioye

πŸ›
Samuel QuiΓ±ones
Samuel QuiΓ±ones

πŸ€”
Manuel
Manuel

πŸ’» πŸ›
Yurii Rybak
Yurii Rybak

πŸ›
Yury Demin
Yury Demin

πŸ› πŸ’»
Jon Tewksbury
Jon Tewksbury

πŸ’» πŸ›
Novac Denis
Novac Denis

πŸ’» πŸ›
kyrylo-soulandwolf
kyrylo-soulandwolf

πŸ’» πŸ›
Miguel Isidoro
Miguel Isidoro

πŸ’»
Yuriy Gromchenko
Yuriy Gromchenko

πŸ’»
Jacob Hummer
Jacob Hummer

πŸ€”
Kyrylo Melnychuk
Kyrylo Melnychuk

πŸ–‹
Luma
Luma

πŸ’»
Eliya Cohen
Eliya Cohen

πŸ’»
Igor Sukharev
Igor Sukharev

πŸ›
pookmish
pookmish

πŸ€”
metav-drimz
metav-drimz

πŸ€”

This project follows the all-contributors specification (emoji key). Contributions of any kind welcome!

πŸ’ž Donate

If you find this piece of software helpful, please consider a donation. Any amount is greatly appreciated.

GitHub Sponsors Paypal Stripe

BTC: bc1qwys40tnd0lxf9lr9l0t6xc63dpxyucj4x4nay0

ETH: 0x36a85155a8300754C56395D5af24553FB18915D6

πŸ“ License

This project is MIT licensed.

About

React hook library, ready to use, written in Typescript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 89.0%
  • JavaScript 8.7%
  • CSS 1.8%
  • Handlebars 0.5%