React custom hooks
There is a collection of React custom hooks, including lifecycle style hooks simulating constructor
, componentDidMount
, componentDidUpdate
, componentWillUnmount
According to https://overreacted.io/a-complete-guide-to-useeffect/
Keep in mind that the mental model for effects is different from componentDidMount and other lifecycles, and trying to find their exact equivalents may confuse you more than help
Install
npm install rhooks
API
useConstructor(fn)
Like in a constructor. Only run once when the function component init.
{ return <div></div>;}
useDidMount(fn)
Like componentDidMount
{ return <div></div>;}
useDidUpdate(fn)
Like componentDidUpdate.
{ return <div></div>;}
useWillUnmount(fn)
Like componentWillUnmount
{ return <div></div>;}
useForceRender(fn)
Force component rerender
{ const forceRender = return <div onClick="() => forceRender()">Date</div>;}
License
MIT