Component with children
Describes how to create components with children
A component class derives from Component and must implement the Render() method. Inside it, local fields, properties, and of course State properties of stateful components are directly accessible and can be used to compose the resulting view.
Components can also render their children by calling the base method Children(). This opens up a powerful feature that can be useful if we want to build a component that arranges its children in some way.
Say we want, for example, to create a component that arranges its children within a customizable grid, like this:

To start, let's create a component that builds our page:
This should show an empty page with just a title, then create a component for our grid (call it WrapGrid)
Every Component class can access its children using the Children() method (it's similar to the {this.props.children} property in ReactJS)
We can add a ColumnCount property and simple logic to arrange and wrap any children passed to the component like this:
Finally, we just need to create the component from the main page and fill it with a list of child buttons:
Last updated
Was this helpful?