Why I use React 18 and createRoot in my PCF controls
Knowledge article · 28 Jul 2026
- Source
- GitHub · README
- Status
- Published
Content
The legacy ReactDOM.render() pattern rebuilds the whole tree on every updateView() and breaks Fluent UI components that rely on positioning.
The problem
Many PCF samples call ReactDOM.render() inside updateView(). With React 16 and that pattern, the whole tree is torn down and rebuilt every time the form notifies a change.
You barely notice it with simple components, but Fluent UI components that depend on @fluentui/react-positioning (such as Combobox or Dialog) can crash reproducibly: the dropdown loses its anchor in the middle of an interaction.
The fix
- Create the root once in
init()withcreateRoot. - In
updateView(), just callroot.render(...)with the new props: React reconciles instead of rebuilding. - Unmount in
destroy()withroot.unmount().
init(context, notify, state, container) {
this.root = createRoot(container);
}
updateView(context) {
this.root.render(<CountryPicker {...props} />);
}
destroy() {
this.root.unmount();
}
A small change that removes a whole family of hard-to-diagnose bugs.
General
- Published
- 28 Jul 2026
- Source
- GitHub · README
- Keywords
- PCFReactFluent UITypeScript
- Related project
- Country Lookup