MCPcopy Create free account
hub / github.com/editablejs/editable / usePrevious

Function usePrevious

packages/ui/src/hooks/use-previous.ts:3–16  ·  view source on GitHub ↗
(value: T)

Source from the content-addressed store, hash-verified

1import * as React from 'react'
2
3function usePrevious<T>(value: T) {
4 const ref = React.useRef({ value, previous: value })
5
6 // We compare values before making an update to ensure that
7 // a change has been made. This ensures the previous value is
8 // persisted correctly between renders.
9 return React.useMemo(() => {
10 if (ref.current.value !== value) {
11 ref.current.previous = ref.current.value
12 ref.current.value = value
13 }
14 return ref.current.previous
15 }, [value])
16}
17
18export { usePrevious }

Callers 1

BubbleInputFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…