Installations
npm install react-hooks-lib
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
14.17.0
NPM Version
6.14.8
Score
77
Supply Chain
98.1
Quality
75
Maintenance
100
Vulnerability
99.6
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
validate.email 🚀
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Developer
Download Statistics
Total Downloads
105,868
Last Day
17
Last Week
145
Last Month
527
Last Year
9,682
GitHub Statistics
MIT License
544 Stars
117 Commits
27 Forks
12 Watchers
11 Branches
4 Contributors
Updated on Feb 18, 2025
Bundle Size
21.18 kB
Minified
6.80 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.6.0
Package Id
react-hooks-lib@0.6.0
Size
719.46 kB
NPM Version
6.14.8
Node Version
14.17.0
Published on
Aug 06, 2021
Total Downloads
Cumulative downloads
Total Downloads
105,868
Last Day
-32%
17
Compared to previous day
Last Week
-13.2%
145
Compared to previous week
Last Month
-28.2%
527
Compared to previous month
Last Year
-41%
9,682
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Peer Dependencies
1
Dev Dependencies
42
React Hooks Lib ·

A set of reusable React Hooks.
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class.
Installation
npm i react-hooks-lib --save
Examples
Visit storybook
Hooks
Name | Arguments | Returns |
---|---|---|
Lifecycles | ||
useDidMount | f | - |
useWillUnmount | f | - |
useDidUpdate | f, conditions | - |
State | ||
createContextState | initial | { ContextProvider, ContextConsumer, set, useSelector, useSet } |
createGlobalState | initial | { GlobalProvider, GlobalConsumer, set, useSelector, useSet } |
useMergeState | initial | { state, set } |
useNestedState | initial | { state, get, set } |
useBind | Please visit storybook | Please visit storybook |
useNestedBind | Please visit storybook | Please visit storybook |
useStateCallback | initial, f | { state, set } |
useUndo | initial | { past, present, future, set, undo, redo } |
useCounter | initial | { count, set, reset, inc, dec } |
useToggle | initial | { on, set, reset, toggle } |
useList | initial | { list, set, reset, push, sort, filter } |
useMap | initial | { values, set, reset, clear, get, has, del } |
Effect | ||
useShallowEqualEffect | f, deps | - |
useDeepEqualEffect | f, deps | - |
Network | ||
useFetch | initialUrl, initialOptions, config | { loading, data, error, fetch, setUrl, setOptions, setData } |
useOnlineStatus | ||
Feedback | ||
useHover | - | { hovered, bind } |
useActive | - | { active, bind } |
useFocus | - | { focused, bind } |
useTouch | - | { touched, bind } |
Data Entry | ||
useField | initial | { value, set, reset, bind } |
Async | ||
useAsync | f | { f, loading } |
API
useDidMount(f)
Similar to componentDidMount
in React class component.
Arguments
f: () => void
: f is called when component did mount.
1import { useDidMount } from 'react-hooks-lib' 2 3const MyComponent = () => { 4 useDidMount(() => { 5 console.log('didMount') 6 }) 7}
useWillUnmount(f)
Close to the componentWillUnmount
in React class component.
Arguments
f: () => void
: f is called when component will unmount.
1import { useWillUnmount } from 'react-hooks-lib' 2 3const MyComponent = () => { 4 useWillUnmount(() => { 5 console.log('willUnmount') 6 }) 7}
useDidUpdate(f, options?)
Similar to componentDidUpdate
, it only runs on updates.
Arguments
f: () => Function | void
: f is called on every updates. LikeuseEffect
, f can return a clean-up function.conditions?: Array<any>
: Optional array for conditionally firing an effect, same as the second argument passed touseEffect
.
1import { useDidUpdate, useCounter } from 'react-hooks-lib' 2 3const MyComponent = () => { 4 const { count, inc } = useCounter(0) 5 useDidUpdate(() => { 6 console.log('DidUpdate') 7 }) 8 return ( 9 <div> 10 {`count: ${count}`} 11 <button onClick={() => inc(1)}>+1</button> 12 </div> 13 ) 14}
createContextState(initial?)
createGlobalState(initial?)
useMergeState(initial?)
Arguments
initial?: Object
: Initial state object, default is{}
.
Returns
state: Object
: Current state object.set: ((Object) => Object) | Object
: LikesetState
in React class component, merge the old and new state together.
1import { useMergeState } from 'react-hooks-lib' 2 3const MergeState = () => { 4 const { state, set } = useMergeState({ name: 'Victor', age: 1 }) 5 return ( 6 <div> 7 <h3>useMergeState</h3> 8 <div> 9 {`state: ${JSON.stringify(state)}`} 10 <button onClick={() => set(({ age }) => ({ age: age + 1 }))}>age+1</button> 11 </div> 12 </div> 13 ) 14}
useNestedState
Arguments
initial?
: Initial state, default isundefined
.
Returns
state
: Current state.get(pathString, defaultValue)
: Get value form state at a specificpathString
. eg:get("a.b.c")
/get("" | undefined)
, ifpathString
is empty,it will return the state object.set: (pathString, newValue | prevValue => newValue)
: Set value at a specificpathString
. eg:set("a.b.c", prev => prev + 1)
/set("" | undefined, {})
. ifpathString
is empty,it will set the entire state object.
useStateCallback(initial, f?)
useUndo(initial)
useCounter(initial)
1import { useCounter } from 'react-hooks-lib' 2 3const Counter = () => { 4 const { 5 count, inc, dec, reset, 6 } = useCounter(1) 7 return ( 8 <div> 9 {count} 10 <button onClick={() => inc(1)}>+1</button> 11 <button onClick={() => dec(1)}>-1</button> 12 <button onClick={reset}>reset</button> 13 </div> 14 ) 15} 16
useToggle(initial)
1import { useToggle } from 'react-hooks-lib' 2 3const Toggle = () => { 4 const { on, toggle, reset } = useToggle(false) 5 return ( 6 <div> 7 {String(on)} 8 <button onClick={toggle}>toggle</button> 9 <button onClick={reset}>reset</button> 10 </div> 11 ) 12}
useList(initial)
1import { useList } from 'react-hooks-lib' 2const List = () => { 3 const { list, sort, filter } = useList([1, 4, 2, 3, 4, 2, 6, 8, 3, 4]) 4 return ( 5 <div> 6 list: 7 {JSON.stringify(list)} 8 <button onClick={() => sort((x, y) => x - y)}>sort</button> 9 <button onClick={() => filter(x => x >= 4)}> greater than or equal to 4</button> 10 </div> 11 ) 12}
useMap(initial)
useFetch(initialUrl, initialOptions?, onMount?)
1import { useField, useFetch } from 'react-hooks-lib' 2 3const Fetch = () => { 4 const getUrl = text => `https://api.github.com/search/repositories?q=${text}` 5 const { value, bind } = useField('react') 6 const { data, loading, setUrl } = useFetch(getUrl('react')) 7 return ( 8 <div> 9 <h3>useFetch</h3> 10 <input type="text" value={value} {...bind} /> 11 <button onClick={() => { 12 setUrl(getUrl(value)) 13 }} 14 > 15 search 16 </button> 17 { 18 loading 19 ? <div>Loading...</div> 20 : (<span>{`total_count: ${data.total_count}`}</span>) 21 } 22 </div> 23 ) 24}
useOnlineStatus()
useHover()
1import { useHover } from 'react-hooks-lib' 2 3const Hover = () => { 4 const { hovered, bind } = useHover() 5 return ( 6 <div> 7 <div {...bind}> 8 hovered: 9 {String(hovered)} 10 </div> 11 </div> 12 ) 13}
useActive()
useFocus()
useTouch()
useField(initial)
1 import {useField} from 'react-hooks-lib' 2 3 const Input = () => { 4 const { value, bind } = useField('Type Here...') 5 6 return ( 7 <div> 8 input text: 9 {value} 10 <input type="text" {...bind} /> 11 </div> 12 ) 13 } 14 15 const Select = () => { 16 const { value, bind } = useField('apple') 17 return ( 18 <div> 19 selected: 20 {value} 21 <select {...bind}> 22 <option value="apple">apple</option> 23 <option value="orange">orange</option> 24 </select> 25 </div> 26 ) 27 }

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 1/14 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 22 are checked with a SAST tool
Reason
138 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-h5c3-5r3r-rr8q
- Warn: Project is vulnerable to: GHSA-rmvr-2pp2-xj38
- Warn: Project is vulnerable to: GHSA-xx4v-prfh-6cgc
- Warn: Project is vulnerable to: GHSA-whgm-jr23-g3j9
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-pp7h-53gx-mx7r
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-4gw3-8f77-f72c
- Warn: Project is vulnerable to: GHSA-257v-vj4p-3w2h
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-phwq-j96m-2c2q
- Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6
- Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-vjh7-7g9h-fjfh
- Warn: Project is vulnerable to: GHSA-6h5x-7c5m-7cr7
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-vfrc-7r7c-w9mx
- Warn: Project is vulnerable to: GHSA-7wwv-vh3v-89cq
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-7r28-3m3f-r2pr
- Warn: Project is vulnerable to: GHSA-r8j5-h5cx-65gg
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-4wx3-54gh-9fr9
- Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj
- Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-7wpw-2hjm-89gp
- Warn: Project is vulnerable to: GHSA-r6rj-9ch6-g264
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-w7rc-rwvf-8q5r
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-5rrq-pxf6-6jx5
- Warn: Project is vulnerable to: GHSA-8fr3-hfg3-gpgp
- Warn: Project is vulnerable to: GHSA-gf8q-jrpm-jvxq
- Warn: Project is vulnerable to: GHSA-2r2c-g63r-vccr
- Warn: Project is vulnerable to: GHSA-cfm4-qjh2-4765
- Warn: Project is vulnerable to: GHSA-x4jg-mjrx-434g
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-px4h-xg32-q955
- Warn: Project is vulnerable to: GHSA-pw54-mh39-w3hc
- Warn: Project is vulnerable to: GHSA-xgh6-85xh-479p
- Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr
- Warn: Project is vulnerable to: GHSA-3j8f-xvm3-ffx4
- Warn: Project is vulnerable to: GHSA-4p35-cfcx-8653
- Warn: Project is vulnerable to: GHSA-7f3x-x4pr-wqhj
- Warn: Project is vulnerable to: GHSA-jpp7-7chh-cf67
- Warn: Project is vulnerable to: GHSA-q6wq-5p59-983w
- Warn: Project is vulnerable to: GHSA-j9fq-vwqv-2fm2
- Warn: Project is vulnerable to: GHSA-pqw5-jmp5-px4v
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-hwj9-h5mp-3pm3
- Warn: Project is vulnerable to: GHSA-wvhm-4hhf-97x9
- Warn: Project is vulnerable to: GHSA-h4hr-7fg3-h35w
- Warn: Project is vulnerable to: GHSA-gj77-59wh-66hg
- Warn: Project is vulnerable to: GHSA-hqhp-5p83-hx96
- Warn: Project is vulnerable to: GHSA-3949-f494-cm99
- Warn: Project is vulnerable to: GHSA-x7hr-w5r2-h6wg
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-5q6m-3h65-w53x
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-r2j6-p67h-q639
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-44c6-4v22-4mhx
- Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-h9rv-jmmf-4pgx
- Warn: Project is vulnerable to: GHSA-hxcc-f52p-wc94
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
- Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6
- Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj
- Warn: Project is vulnerable to: GHSA-wpg7-2c88-r8xv
- Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq
- Warn: Project is vulnerable to: GHSA-w5hq-hm5m-4548
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw
- Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-38fc-wpqx-33j7
- Warn: Project is vulnerable to: GHSA-9m6j-fcg5-2442
- Warn: Project is vulnerable to: GHSA-hh27-ffr2-f2jc
- Warn: Project is vulnerable to: GHSA-rqff-837h-mm52
- Warn: Project is vulnerable to: GHSA-8v38-pw62-9cw2
- Warn: Project is vulnerable to: GHSA-hgjh-723h-mx2j
- Warn: Project is vulnerable to: GHSA-jf5r-8hm2-f872
- Warn: Project is vulnerable to: GHSA-wr3j-pwj9-hqq6
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
2
/10
Last Scanned on 2025-03-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to react-hooks-lib
@use-it/event-listener
A custom React Hook that provides a useEventListener.
use-persisted-state
A custom React Hook that provides a multi-instance, multi-tab/browser shared and persistent state.
@szaranger/react-hooks-lib
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
@alexandreannic/react-hooks-lib
Bunch of react hooks