useValue
Signature
useValue<T>(state: Atom<T> | Selector<T>): Ref<T>valdres-vue Read-only subscription to state
A read-only composable that returns a reactive Ref for an atom or selector. The ref updates whenever the underlying state changes.
Usage
<script setup>
import { atom, selector } from "valdres"
import { useValue } from "valdres-vue"
const nameAtom = atom("Valdres")
const greetingSelector = selector(get => `Hello, ${get(nameAtom)}!`)
const greeting = useValue(greetingSelector)
</script>
<template>
<h1>{{ greeting }}</h1>
</template>
See also
- useAtom — read + write composable
- useSetAtom — write-only composable