Skip to content

Commit 009b7f0

Browse files
committed
remove useLatestRef altogether
1 parent a9be060 commit 009b7f0

4 files changed

Lines changed: 5 additions & 29 deletions

File tree

src/hooks/utils/useEnhancedReducer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react'
22

3-
import {getState, useLatestRef} from '../../utils'
3+
import {getState} from '../../utils'
44
import {callOnChangeProps} from './callOnChangeProps'
55
import {type Action, type Props, type Reducer} from './index.types'
66

@@ -48,7 +48,10 @@ export function useEnhancedReducer<
4848
lastAction: undefined,
4949
}),
5050
)
51-
const propsRef = useLatestRef(props)
51+
const propsRef = React.useRef(props)
52+
React.useEffect(() => {
53+
propsRef.current = props
54+
}, [props])
5255
const dispatchWithProps = React.useCallback(
5356
(action: A) => dispatch({...action, props: propsRef.current}),
5457
[propsRef],

src/utils/__tests__/useLatestRef.test.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/utils/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export {generateId, setIdCounter, resetIdCounter} from './generateId'
2-
export {useLatestRef} from './useLatestRef'
32
export {handleRefs} from './handleRefs'
43
export {callAllEventHandlers} from './callAllEventHandlers'
54
export {debounce} from './debounce'

src/utils/useLatestRef.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)