Refactor(TS): Rename some file from *.tsx to *.ts
This commit is contained in:
21
src/util/hooks.ts
Normal file
21
src/util/hooks.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { DependencyList, EffectCallback } from 'react'
|
||||
|
||||
export const useUpdatedEffect = (effect: EffectCallback, dependencies: DependencyList) => {
|
||||
const isFirstRender = useRef(true)
|
||||
|
||||
useEffect(() => {
|
||||
if (isFirstRender.current) {
|
||||
isFirstRender.current = false
|
||||
} else {
|
||||
return effect()
|
||||
}
|
||||
}, dependencies)
|
||||
}
|
||||
|
||||
export const usePrevious = <T,>(value: T): T | undefined => {
|
||||
const ref = useRef<T>()
|
||||
useEffect(() => {
|
||||
ref.current = value
|
||||
})
|
||||
return ref.current
|
||||
}
|
||||
Reference in New Issue
Block a user