You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
312 B
TypeScript
18 lines
312 B
TypeScript
1 year ago
|
import { ref, watch } from 'vue'
|
||
|
import type { Ref } from 'vue'
|
||
|
|
||
|
const usePrevious = <T>(state: Ref<T>): T | undefined => {
|
||
|
const innerState = ref<T>()
|
||
|
|
||
|
watch(
|
||
|
() => state.value,
|
||
|
(newVal, oldVal) => {
|
||
|
innerState.value = oldVal
|
||
|
}
|
||
|
)
|
||
|
|
||
|
return innerState.value
|
||
|
}
|
||
|
|
||
|
export default usePrevious
|