useTextField function

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

function useTextField<TClient extends ViewClient>(view: TextFieldView<TClient>, read: (state: TClient["snapshot"]) => string, write: (client: TClient, value: string) => Promise<unknown>, options?: UseTextFieldOptions): TextFieldHandle;

Binds a text input to one member of a View while the current effect scope is active, through createTextFieldController. Typing key by key never loses characters: while its writes are in flight the field shows what the user typed, at most one write is in flight (newer text is written next), and once the last write settled it shows the View's value, including any normalization. Each field is a ref, so the handle can be destructured. Call it in setup() or effectScope().run(): outside an effect scope it is never released (development builds warn).

const person = useView(() => props.page);
const { value: name, editing } = useTextField(person, state => state.name, (client, value) => client.setName(value));
<input v-model="name">

write may be a generated setter, a command or a checked write. Its failure, and a checked write's rejected or conflict receipt, keep the draft and set error (a receipt's is a FieldError). For a generated member, prefer useField with its {View}Fields descriptor.