useField function

Module @runic-artifex/svelte in @runic-artifex/svelte 0.23.0

function useField<TClient extends ViewClient, TValue>(view: () => TextFieldView<TClient>, field: BridgeField<NoInfer<TClient>, NoInfer<TClient>["snapshot"], TValue> | FieldDefinition<NoInfer<TClient>, NoInfer<TClient>["snapshot"], TValue>, options?: FieldOptions<TValue>): FieldHandle<TValue>;

Binds an element to one View member while the calling component is mounted, through createFieldController: pass a generated descriptor such as EditorFields.title, or any definition with read and write. Call it during component initialization; options are read then. Wire the element with {@attach title.attach}, or bind bind:value={title.value} and call commit on blur yourself.

const editor = useView(() => page);
const title = useField(() => editor, EditorFields.title, { commit: "pause", checked: true });
<input {@attach title.attach}>
{#if title.conflict}<button onclick={title.retry}>Keep mine</button>{/if}

With checked: true a rejected or conflict receipt keeps the draft and sets error (a FieldError), and a conflict holds further writes until retry() or reset(). Unmounting writes a value that waits to be written.