Skip to Content
API ReferenceStatelessElement

StatelessElement

live An element that composes other elements but holds no mutable state. Override the Build method to describe the UI subtree this element represents. The framework calls Build whenever the parent rebuilds, and the returned element tree is reconciled against the previous output.

Constructor

StatelessElement

Creates a new stateless element with an optional key.

ParameterDescription
keyAn optional key for reconciliation identity.

Methods

Build

Describes the UI subtree that this element represents. Called by the framework whenever a rebuild is needed.

ParameterDescription
contextThe build context providing access to the element’s position in the tree and ancestor lookup capabilities.

Returns: An element describing the UI subtree.

ShouldRebuild

Called by the framework before rebuilding this element when its parent rebuilds. Return false to skip Build(), child reconciliation, and repaint entirely. Return true (the default) to rebuild as normal. Override this to avoid rebuilding when the new element description is equivalent to the previous one.

ParameterDescription
oldElementThe previous element description.
newElementThe incoming element description from the parent.

Returns: true to rebuild; false to skip.

ShouldRebuild

Last updated on