Skip to content

🧩 Readonly & Optimized State Hooks ​

Stunk gives you simple hooks to read state efficiently β€” perfect for components that don’t need to modify anything.

πŸ” useChunkValue ​

A lightweight hook that subscribes to a chunk and returns only its current value.
Ideal for read-only components.

tsx
import { chunk } from "stunk";
import { useChunkValue } from "stunk/react";

const count = chunk(0);

function CounterDisplay() {
  const value = useChunkValue(count);
  return <p>Count: {value}</p>;
}

βœ… No extra functions β€” just reads the value βœ… Selector support β€” read a specific part of the chunk

tsx
const user = chunk({ name: "Fola", age: 30 });

function UserAge() {
  const age = useChunkValue(user, (u) => u.age);
  return <p>Age: {age}</p>;
}

🧱 useChunkProperty ​

Subscribe to a single property inside an object chunk. The component re-renders only when that property changes.

tsx
import { chunk } from "stunk";
import { useChunkProperty } from "stunk/react";

const user = chunk({ name: "Abdulzeez", age: 25 });

function UserName() {
  const name = useChunkProperty(user, "name");
  return <p>Name: {name}</p>;
}

βœ… Prevents extra re-renders βœ… Perfect for object-based state

πŸ”— useChunkValues ​

Read multiple chunks at once. Re-renders only when any of them change.

tsx
const firstName = chunk("Qudus");
const lastName = chunk("Asake");

function FullName() {
  const [first, last] = useChunkValues([firstName, lastName]);
  return <p>{first} {last}</p>;
}

βœ… Reactive across multiple chunks βœ… Clean and easy to read

⚑ Summary ​

HookPurpose
useChunkValueRead-only access to a chunk
useChunkPropertySubscribe to one property only
useChunkValuesCombine values from multiple chunks

These keep your components fast, reactive, and clean β€” no wasted re-renders, no boilerplate. πŸš€