v0 · Developer Preview Frond is under active development. APIs may change between releases.

useNodeState

useNodeState(spec, args) returns the ready node instance plus its live lifecycle. It has the same readiness behavior as useNode and adds the node’s operation state. Use it to show a refresh spinner over the current value, or to mark data stale while it reloads.

import * as FrondReact from "@frondruntime/react";
import { observer } from "mobx-react-lite";

const ProfilePanel = observer(({ userId }: { userId: string }) => {
  const state = FrondReact.useNodeState(ProfileNode, { userId });

  return (
    <div>
      <h1>{state.node.displayName}</h1>
      {state.busy && <Spinner />}
    </div>
  );
});

Wrap the component in observer when it renders state.node fields, getters, or result-backed data. You do not need observer for components that only read lifecycle metadata such as state.busy, state.operation, state.operationFailure, or state.nodeId; those update through the hook subscription.

Returns

FieldTypeDescription
nodenode instanceThe ready node.
nodeIdNodeIdThe graph node id.
operationNodeOperation{ _tag: "Idle" } or { _tag: "Running", kind } where kind is "action", "refresh", or "args".
busybooleantrue while an operation is running.
operationFailureNodeOperationFailure | undefinedThe last operation failure, if any.
resultValidityDisplayableResultValidity{ _tag: "Current" | "Stale" }.

Same readiness behavior as useNode

useNodeState suspends until the node is ready and throws readiness failures to the nearest error boundary, exactly like useNode — in fact useNode returns useNodeState(...).node. When the hook returns, state.node is always a ready node. See Suspense and errors.

It adds the lifecycle that happens after readiness. A background operation — a refresh or an action — runs against the already-ready node without suspending. useNodeState exposes it through operation and busy, which useNode does not return:

{state.busy && <Spinner />}
{state.resultValidity._tag === "Stale" && <StaleBadge />}

Expired data is not background work and is not exposed as ready render data. The hook schedules readiness, suspends, and reloads. See Result validity.

When to use which

HookReturnsUse for
useNodethe ready nodeThe common read.
useNodeStatenode + operation/busy/validityReflecting refreshes, actions, or stale data in the UI.

Next: useNodeControls — refresh, evict, and release without reading the result.