Study FAQ
How should a PCF control handle host updates, user edits and cleanup?
Also asked as 2
- What do init, updateView, notifyOutputChanged, getOutputs, and destroy do in a PCF field control?
- How do I send a validated PCF field edit without creating a second Dataverse save path?
Answer
Receive host state through updateView, emit a valid user edit through notifyOutputChanged and getOutputs, and let the host save the bound value. Keep control creation and cleanup in the lifecycle methods.
In a standard field control, init creates owned elements, registers handlers once and stores the output callback. Request resize tracking there if needed. updateView receives the latest properties, layout and disabled state. Reconcile display without emitting changes on render. Keep empty or not-yet-loaded values distinct from zero and define how a host update affects an in-progress edit.
On a valid changed commit, store the output, call notifyOutputChanged and return the value under the manifest property name from getOutputs. Show invalid-input feedback without emitting a replacement. Keep saves in the host flow to avoid racing a second API write. In destroy, remove listeners, timers, observers and rendering resources, and ignore async completions that arrive after disposal.
Test a null value, a valid zero, an invalid entry, a disabled control and repeated resizes. Save a valid edit through the app, reopen the row and check persistence. For a whole-number range, include blank text, a fraction and out-of-range values. Decide separately whether clearing is supported. Repeat with keyboard interaction, narrow layout and accessible labels.
StandardControl lifecycle · Implement a code component in TypeScript
Full explanation
AB-400: Building Reusable PCF Code Components
Study guide · AB-400
Read the full explanation