API reference · generated from source
Read the guide →Function: useRaw()#
function useRaw<TNode>(node, options?): [TNode, ToManaged];Defined in: useRaw.ts:91
Subscribe to a node like useNode, but read its data raw — native-speed,
proxy-free reads for render bodies that read wide.
Type Parameters#
| Type Parameter |
|---|
TNode extends object |
Parameters#
| Parameter | Type | Description |
|---|---|---|
node | | TNode | NodeFactory<TNode> | Retree-managed node or node factory to observe. |
options? | UseRawOptions | Optional listener type. |
Returns#
[TNode, ToManaged]
[raw, toManaged] tuple.
Remarks#
Returns [raw, toManaged]:
rawis the live raw object behind the node (Retree.raw) — zero-copy and guaranteed proxy-free. Treat it as read-only: writes go through nodes. Raw references keep the same identity across changes, so never use them asReact.memoprops,useMemodeps, or equality tokens — nodes remain the identity currency.toManagedresolves a raw value back to its managed node. Direct children of the subscribed node always resolve (object/array children, Map values, and Set members are materialized on demand); use it to pass nodes to child components while mapping raw content.
Invalidation follows the same contract as useNode: the component
re-renders when the node's own data changes (nodeChanged default). Deep
changes re-render only when declared — via the node's dependencies /
@select, via useSelect for derived views, or via the treeChanged
opt-in. Because raw is live, any render (including renders triggered by
a parent) reads current state.
Example#
function TaskListView({ list }: { list: TaskList }) {
// Re-renders only when the array itself changes.
const [tasksRaw, toManaged] = useRaw(list.tasks);
return (
<ul>
{tasksRaw.map((rawTask) => (
<TaskRow key={rawTask.id} task={toManaged(rawTask)!} />
))}
</ul>
);
}
const TaskRow = React.memo(function TaskRow({ task }: { task: Task }) {
const t = useNode(task); // node prop: own subscription, write surface
return <li onClick={() => (t.isComplete = !t.isComplete)}>{t.title}</li>;
});