Function: setNodeProp()
setNodeProp(
version,nodeId,path,value):DocumentVersion
Defined in: packages/core/src/setNodeProp.ts:39
Sets one prop on one node, addressed by a dotted path into that node's props.
The value is not checked against the block's schema here. compile reports a bad one as an
invalid-props issue at the offending path, so a document may hold a value its schema
rejects between two edits that end valid.
Parameters
version
The document to edit. Read, never written.
nodeId
string
Id of the node whose props are rewritten. The document must hold it.
path
string
Dotted path into the node's props, in the syntax setAtPath defines:
headline, cta.label. Missing intermediate objects are created; items[] is refused.
value
unknown
What to write at that path. Unvalidated, and replaces whatever sits there.
Returns
A new DocumentVersion carrying a new Node for nodeId with the prop set. The
argument is not mutated, version.version, roots, meta and createdAt are untouched,
and every other node is carried over by reference.
Throws
no-such-node when nodeId names a node the document does not hold;
path-not-addressable when the path names no single field — an items[] segment, an empty
segment, or a descent into an array.
Example
const next = setNodeProp(version, "hero", "headline", "After");
next.elements.hero?.props.headline; // "After"
// A dotted path reaches inside an object prop, leaving its siblings in place.
setNodeProp(version, "hero", "cta.label", "Buy").elements.hero?.props.cta;
// { label: "Buy", href: "/" }