useGetterRef

A React Hook that create a gettable ref, a function way to get the latest value of a ref.

Demo

Try to increase the counter and then toast the latest ref value.

NOTE: Changes in the ref value will not trigger a re-render, you should call render to update the UI.

Source
Value:
0
Is open:
false

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

const [ref, getter] = useGetterRef(initialValue)

InitialValue

Initial value of the ref.

Returns

export type UseGetterRefReturns<T> = [ /** * A mutable ref object that can be used to store a value. */ ref: React.MutableRefObject<T>, /** * A getter function that returns the current value of the ref. */ getter: () => T, ]