Skip to main content

resolveEditable()

resolveEditable(editable, [args], [{ targetKey, field }]);

Composes a usage's keys, and the attributes that render them.

export function Headline(props) {
const { attrs } = resolveEditable(editable, props, { targetKey: useTargetKey() });

return <h1 {...attrs}>{props.children}</h1>;
}

Arguments​

ArgumentTypeDescription
editableObjectWhat defineEditableSource() returned.
argsObjectThe usage's arguments: props, constructor options, or whatever the render function was called with.
options.targetKeyStringFills {targetKey}. Required where a key uses it.
options.fieldStringWhich field, where the declaration names several.

A key with no placeholders needs neither: resolveEditable(editable).

Returns​

// Headline declares everyone: { key: "{targetKey}-{id}-{instance}" },
// personal: { when: prop("hasPersonalChannel"), key: "{targetKey}-{id}-{instance}" }
resolveEditable(
editable,
{ id: "title", hasPersonalChannel: true },
{ targetKey: "plans" },
);

{
type: "text",
keys: { everyone: "plans-title-{instance}", personal: "plans-title-{instance}" },
ids: { everyone: "title", personal: "title" },
attrs: {
"data-companywide-editable": "plans-title",
"data-editable": "plans-title",
},
description: undefined,
}

{instance} stays in keys exactly like this. The slide fills it in once it renders, from wherever it is placed - see {instance}.

Every attribute carries the field's name instead, with no {instance} in it. That is what reads the field back later, and no CSS selector accepts a brace. What ends up in the page is this:

<h1 data-companywide-editable="plans-title" data-editable="plans-title">Plans that grow with you</h1>

type​

The field's type, after prop() is read.

keys​

The key for each channel the usage uses. Hand these to a component that stores through its own API rather than through markup.

ids​

The id behind each key.

attrs​

The attributes to spread onto the element. Render these where the component renders its own element.

Typeeveryonepersonal
text, richtextdata-companywide-editabledata-editable
imagedata-companywide-dynamic-imagedata-dynamic-image
videodata-companywide-youtube-player

A toolbar adds data-toolbar.

description​

What the field is for. Never rendered.