Skip to main content

useRef

Callable

  • useRef<V>(hostObject: Storage | Ref<Record<string | symbol, unknown>>, key: string, initialValue: V): Ref<V>

  • Return a new Ref stored at storage.get(key) or ref.value[key]

    @example
    const globalStorage = useStorage(globalThis);
    const counterRef = useRef<number>(globalStorage, 'counter', 1);
    // globalStorage == Map { counter => 1 }

    const state = Ref({});
    const counterRef = useRef<number>(state, 'counter', 2);
    // state == { counter: 2 }

    Type parameters

    • V