Skip to content

Commit 363c52b

Browse files
feat: implement componentDidUpdate function to pass the test
1 parent f42f6d1 commit 363c52b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,18 @@ const useLifecycleHelpers = (state = {}, props = {}) => {
3333
const useComponentDidUpdate = (
3434
callback
3535
) => {
36+
const isFirstRender = useRef(true)
3637

38+
useEffect(() => {
39+
if (isFirstRender.current) {
40+
isFirstRender.current = false
41+
} else {
42+
callback(prevState, prevProps)
43+
setPrevState(state)
44+
setPrevProps(props)
45+
}
46+
// eslint-disable-next-line
47+
}, [state, props])
3748
}
3849

3950
/**

0 commit comments

Comments
 (0)