MSBA-271 · Lesson 5 of 12 · 19 min

Power Apps component framework

▶ Video coming soon A video version of this lesson is on the way.

In MSBA-270, Wiremu had asked where the floor plan control for Facilities Hub would go, and Signe had told him to wait. This session was the start of the answer. "A business rule cannot draw a floor plan, a script should not, and a custom page is too heavy for a field on a form," she said. "This is what code components are for."

What the component framework is

The Power Apps component framework lets developers build code components: reusable controls, written in TypeScript, that replace or extend the standard controls Power Apps uses to show and edit data. A code component can show a column on a form as a slider, a star rating, a map or a floor plan; it can show a whole view or subgrid as a calendar, a board or a chart. Unlike HTML web resources, which sit in their own frame and talk to the form through scripts, code components are first-class parts of the app. They receive data from the host, are drawn with the rest of the page, can be configured by makers without code, and are packaged in solutions like any other component.

Microsoft and the community publish many code components, and Microsoft's own newer controls use the same framework. For a developer, the framework's value is that one well-built control can be dropped into many forms, views and apps by makers, with properties they set in the designer.

Code components compared with other ways to add custom user interface.
ApproachWhere it runsStrengthWeakness
Code componentInside the form, view, canvas screen or custom pageReusable, configurable, bound to data, part of the pageNeeds TypeScript, a build and packaging
HTML web resourceIn a frame on a form or as a pageAny web contentIsolated; data access through scripts; poor fit with modern forms
Custom pageAs a page or dialog in a model-driven appFree layout, connectors, low-codeHeavier than a field control; not a column replacement
Code appAs its own app hosted by Power PlatformFull web framework, whole appA separate app, not a control inside another

Field and dataset components

Code components come in two types. A field component is bound to one column, or to a small set of properties, and replaces the control for that column on a form or a single control in a canvas app. A star rating bound to a whole number column is a field component. A dataset component is bound to a set of rows, such as a view or subgrid, and replaces the grid. A Kanban board bound to a work order view is a dataset component. The type is chosen when the project is created and shapes everything else: field components work with values, dataset components work with records, paging, sorting and filtering supplied by the host.

RoomPicker, the floor plan control, could be built either way. As a field component it would be bound to the Location lookup on the work order and show the room on a plan, letting the dispatcher click a different room. As a dataset component it would show every room in a building, colored by open jobs. Signe and Wiremu decided on a field component for the form, and left the dataset idea for later, because the form was where dispatchers needed it.

Standard and React components

There are two interfaces a code component can implement. A standard component receives an HTML element in init and draws into it however it likes, with plain DOM code or any library it bundles. A React component, which Microsoft also calls a virtual component, does not draw into the page itself. Its updateView method returns a React element, and the platform draws it using shared platform libraries: React and, optionally, Fluent UI, loaded once by the host rather than bundled into each control. Microsoft announced general availability of React and Fluent-based virtual code components in December 2024 and describes them as the expected preferred way to build code components.

Standard and React code components.
Standard componentReact (virtual) component
Manifest control-typestandardvirtual
init receivesAn HTML container elementNo container element
updateView returnsNothing; the component updates its own DOMA React element
React and FluentBundled by the component if usedShared platform libraries declared in the manifest
Bundle sizeLarger if it bundles librariesSmaller
HostsModel-driven apps, custom pages, canvas apps, Power PagesModel-driven apps, custom pages and canvas apps; not Power Pages
A grid of hosts: model-driven apps, custom pages, canvas apps and Power Pages. Standard components show yes for all four. React virtual components show yes for the first three and no for Power Pages.
Host support for standard and React code components.

Platform libraries come with version rules. The manifest declares the React version and either Fluent 8 or Fluent 9, never both, within ranges Microsoft documents; at run time the app may load a higher compatible version. Microsoft's documentation in late 2026 listed React 16.14.0 as the version to declare, with React 17.0.2 loaded in model-driven apps and 16.14.0 in canvas apps. An existing standard component cannot be converted by changing its control type; the developer creates a new React project and moves the logic.

Wiremu, a React developer, was delighted. Signe tempered it: React components cannot be used in Power Pages, where a React control does not update when other fields change, so the contractors' portal would need a different approach if it ever wanted the floor plan. For Facilities Hub and the canvas Field Tech app, React was the right choice.

The lifecycle

Every code component implements a small set of methods that the host calls in a fixed order. Understanding the order is the key to writing components that behave.

A lifecycle diagram. init leads to updateView. updateView and getOutputs exchange values: after notifyOutputChanged the host calls getOutputs, and the host sends new values back through updateView. A dashed arrow leads from getOutputs to destroy. A note says updateView runs again whenever data, size or mode changes.
The code component lifecycle.
The four lifecycle methods.
MethodWhen it runsWhat it should do
initOnce, when the component is createdKeep the context and the notifyOutputChanged callback; set up event handlers; for standard components, create the root element in the container
updateViewAfter init and whenever a bound value, the size, the mode or other context changesDraw or redraw from the current context; React components return the element tree
getOutputsWhen the host asks for values, after the component calls notifyOutputChangedReturn the changed output property values
destroyWhen the component is removed from the pageRemove event handlers, timers and other resources

The flow of a value is worth tracing once. When the dispatcher clicks room 102 on the floor plan, the component stores the new room internally and calls notifyOutputChanged. The host responds by calling getOutputs, which returns the new Location value. The host writes it to the form's attribute, which may run OnChange handlers and business rules, and then calls updateView with the updated context so the control can draw the final state. A component that changes its own display directly on click, without waiting for updateView, can end up showing a value the form has rejected.

The most common lifecycle bug is doing heavy work in updateView. Because it runs often, sometimes several times in a row, anything expensive there, such as fetching data or rebuilding a large drawing, makes the form sluggish. The rule is to compare the new context with what is already drawn and do only what changed. Another common bug is forgetting destroy: a component that adds a window resize listener and never removes it keeps running after the form closes.

The context object

Everything a component learns about its surroundings comes through the context object passed to init and updateView. context.parameters holds the bound properties and their current values. context.mode reports whether the control is disabled or hidden and how much space it has. Other members give access to services provided by the host.

Main members of the code component context.
Context memberGives the component
parametersBound and input property values, or the dataset for dataset components
modeDisabled state, visibility, allocated width and height, and trackContainerResize
userSettings and clientThe user's language, time zone and the client form factor
formattingFormatting of dates, numbers and currency in the user's settings
resourcesStrings from resx files and other resources declared in the manifest
utilsUtility methods such as entity metadata, and lookups
navigationOpening forms, URLs, alerts and confirm dialogs
deviceCamera, barcode, location and file capture where the host supports them
webAPICreate, retrieve, update and delete Dataverse rows where the host supports it

Not every member works in every host, and the manifest's feature-usage section is how a component says what it needs. Each uses-feature element names a feature, such as WebAPI or Device.captureImage, and marks it required or not. If a required feature is not available in the host, the component fails to load and the designer shows a warning; if it is not required, the component loads and should check at run time whether the feature exists and adapt. Microsoft's uses-feature reference lists model-driven apps as the host it is available for, so components that rely on webAPI or device features should be tested in each host they target and should degrade gracefully.

Worked problem

Choosing the component type and interface

Three requests reach Wiremu: a star rating for the inspection quality column in Facilities Hub and the Field Tech canvas app; a board view of work orders grouped by status; and a signature pad for the contractors' Power Pages site. Which type and interface fits each?

Show solution
  1. The star rating replaces one column in two hosts, model-driven and canvas. A field component fits, and a React interface with Fluent keeps it small and consistent with the app's look; both hosts support React components.
  2. The board shows many rows grouped by a column. That is a dataset component bound to a work order view. React suits it as well.
  3. The signature pad must work in Power Pages, which does not support React components. It should be a standard field component, drawing on a canvas element it creates in its container.

Answer: A React field component, a React dataset component and a standard field component. The host list decides the interface as much as the developer's preference.

When not to build a component

The best code component is often the one that is never written. Before starting any component, Signe asked three questions. Does a standard control, or one of Microsoft's newer built-in controls, already do this? Can the need be met with form configuration, a business rule or a canvas custom page? And who will maintain the component when it needs to change? Only if the answers were no, no and a named developer did a component go on the plan.

Alternatives to check before building a component.
NeedTry firstBuild a component when
A better way to show a numberStandard controls and formattingThe display needs custom drawing, such as RoomCapacity's bar
Editing rich textThe built-in rich text editor controlNever, for Lumenvale's needs
A better gridThe Power Apps grid control and its settingsThe grid needs a layout the standard control cannot offer
A multi-step taskA canvas custom pageThe task must replace a field's control in place

Security and licensing

A code component runs in the user's browser with the user's identity. Data it reads through context.webAPI is subject to the user's security roles, exactly as for the standard control, so a component cannot show a user anything they could not already see. That also means a component must never contain secrets, such as keys for an outside service, because anything shipped to the browser can be read by anyone who opens developer tools.

Components that call outside services directly from the browser, rather than through connectors, must declare it in the manifest with an external-service-usage element listing the domains they call. This matters for licensing as well as transparency: Microsoft treats code components that connect to external services directly as premium components, and an app that uses one requires premium licenses for its users. RoomCapacity and the planned RoomPicker used only Dataverse, which kept them out of that category.

Common mistakes

  • MistakeBuilding a React component for Power Pages.

    InsteadUse a standard component where Power Pages must host it.

  • MistakeDoing heavy work in every updateView call.

    InsteadCompare the new context with the drawn state and change only what differs.

  • MistakeUpdating the display directly on click and skipping the output round trip.

    InsteadCall notifyOutputChanged and redraw from updateView, so the control shows what the host accepted.

  • MistakeLeaving listeners and timers running.

    InsteadRemove them in destroy.

  • MistakeDeclaring both Fluent 8 and Fluent 9.

    InsteadChoose one Fluent version per manifest.

Summary and key terms

  • The component framework builds TypeScript code components that replace or extend standard controls in model-driven apps, custom pages, canvas apps and Power Pages.
  • Field components bind to a column; dataset components bind to a set of rows.
  • Standard components draw into a container; React components return React elements and use shared React and Fluent platform libraries, which are not supported in Power Pages.
  • The lifecycle is init, updateView (often), getOutputs after notifyOutputChanged, and destroy.
  • The context object provides parameters, mode, formatting, resources, utils, navigation, device and webAPI; feature-usage declares what the component needs.
Code component
A reusable TypeScript control built with the Power Apps component framework.
Field component
A code component bound to a column or a small set of properties.
Dataset component
A code component bound to a set of rows such as a view or subgrid.
React (virtual) component
A code component whose updateView returns a React element drawn with shared platform libraries.
Platform library
A shared library such as React or Fluent that the host loads once for all React components.
notifyOutputChanged
The callback a component calls to tell the host it has new output values.
uses-feature
A manifest element that declares a host feature, such as WebAPI, that the component needs.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. In what order does the host call the lifecycle methods when a user changes a value in a component?

    Show answer

    The component calls notifyOutputChanged, the host calls getOutputs, writes the value, then calls updateView with the new context.

  2. Why can a React component not be used on a Power Pages site?

    Show answer

    Power Pages does not support React components; they do not update when other fields change there. Use a standard component.

  3. What happens if a component marks a feature as required and the host lacks it?

    Show answer

    The component fails to load and the designer shows a warning.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz