read
The Statety.read
function is used to retrieve the current value of a state key. It returns a snapshot of the state at the moment it’s called. Note that Statety.read
does not automatically subscribe your component to future updates — use useStatety
or Statety.subscribe
for reactive behavior.
TypeScript Signature
Section titled “TypeScript Signature”Statety.read<T>(key: AnyStatetyKey<T>): T | null
Parameters
Section titled “Parameters”key
– The key identifying the state to read. Can be a basic, derived, or computed state key.
Returns
Section titled “Returns”T | null
– The current value associated with the key.
Example
Section titled “Example”import { Statety } from "statety";
const USER_KEY = Statety.create<{ username: string; role: string }>("user", { username: "guest", role: "visitor",});
const user = Statety.read(USER_KEY);console.log(user?.username); // Output: "guest"