A developer is building a standard field code component with the Power Apps component framework. The component must create its input element once, attach event listeners to it, and keep a reference to the callback that tells the framework its outputs changed. In which lifecycle method should this setup happen?
Select an answer to reveal the explanation.
Short Explanation
Think of init as move-in day: you build the furniture, hook up the doorbell and keep the house keys. updateView is every later visit when something changes, so if you rebuild the DOM there you'll stack duplicate listeners every time a value updates.
Full Explanation
The component framework calls init once when the component is first loaded. For a standard control, init receives the context with the property bag and framework APIs, the notifyOutputChanged callback the component calls when it has new output values, a state object for persisted state, and the container div the component renders into. Creating DOM elements, attaching event listeners and storing references to the container and the callback all belong here, because they should happen exactly once per component instance. updateView is called after init and then again whenever property values, size, metadata or other context information changes, so it is for refreshing what is displayed from the current context; creating elements there would duplicate them on every update, and it does not receive the container or the callback. getOutputs is called by the framework after the component signals a change, to collect values to write back to bound properties; it has nothing to do with initial rendering. The class constructor runs without framework arguments, so it cannot receive the container or the context, and the framework's documented entry point is init. Exam caveat: React-based virtual components do not receive a container in init, because their updateView returns a React element. Operational check: add a log statement to init and updateView in the test harness and confirm init runs once while updateView runs on each change.