1717 <img src="https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
1818 </a >
1919 <a href =" https://www.npmjs.com/package/@better-hooks/lifecycle " >
20- <img src="https://custom-icon-badges.demolab.com/bundlephobia/min /@better-hooks/lifecycle?color=64BC4B&logo=package " />
20+ <img src="https://custom-icon-badges.demolab.com/npm/v /@better-hooks/lifecycle.svg?logo=npm&color=E10098 " />
2121 </a >
2222 <a href =" https://www.npmjs.com/package/@better-hooks/lifecycle " >
23- <img src="https://custom-icon-badges.demolab.com/npm/v/@better-hooks/lifecycle.svg?logo=npm&color=E10098" />
23+ <img src="https://custom-icon-badges.demolab.com/bundlephobia/minzip/@better-hooks/lifecycle?color=blueviolet&logo=package" />
24+ </a >
25+ <a href =" https://www.npmjs.com/package/@better-hooks/lifecycle " >
26+ <img src="https://custom-icon-badges.demolab.com/npm/dm/@better-hooks/lifecycle?logoColor=fff&logo=trending-up" />
2427 </a >
2528</p >
2629
@@ -36,6 +39,8 @@ React lifecycle turned into dev friendly and readable hooks
3639
3740💎 ** No external dependencies**
3841
42+ 🪄 ** Increases code readability**
43+
3944## Installation
4045
4146``` bash
@@ -54,9 +59,17 @@ yarn add @better-hooks/lifecycle
5459
5560``` tsx
5661import React from " react" ;
57- import { useDidMount , useDidRender , useDidUpdate , useWillUnmount ,useIsMounted , useWillMount } from " @better-hooks/lifecycle" ;
58-
59- const MyComponent: React .FC = () => {
62+ import {
63+ useDidMount ,
64+ useDidUpdate ,
65+ useWillUnmount ,
66+ useIsMounted ,
67+ useWillMount ,
68+ useForceUpdate ,
69+ useDidChange
70+ } from " @better-hooks/lifecycle" ;
71+
72+ const MyComponent: React .FC = (props ) => {
6073 const [isOpen, setIsOpen] = React .useState (false )
6174
6275 // returns ref with the mounted boolean state
@@ -75,11 +88,6 @@ const MyComponent: React.FC = () => {
7588 // ...
7689 })
7790
78- // Called second, when initial DOM changes are triggered
79- useDidRender (() => {
80- // ...
81- })
82-
8391 // Called when isOpen change
8492 useDidUpdate (() => {
8593 // ...
@@ -90,6 +98,13 @@ const MyComponent: React.FC = () => {
9098 // ...
9199 }, [isOpen ], true )
92100
101+ // Called when dependencies change, we can inspect previous dependencies
102+ useDidChange ((prevProps ) => {
103+ if (prevProps .value !== props .value ) {
104+ // ...
105+ }
106+ }, [props ], true )
107+
93108 // Called last
94109 useWillUnmount (() => {
95110 // ...
0 commit comments