> For the complete documentation index, see [llms.txt](https://adospace.gitbook.io/reactorui/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://adospace.gitbook.io/reactorui/guide/components-with-a-state/component-with-children.md).

# Component with children

Any component deriving from `RxComponent` can render anything in its `Render()` overload.&#x20;

Sometimes is useful a component that arranges children.&#x20;

Say we want for example to create a component that arranges its children within a customizable grid, like this:

![](/files/-M4fDrbOnPziSVzcjVOK)

To start let's create a component that build our page:

```csharp
public class PageComponent : RxComponent
{
    public override VisualNode Render()
    {
        return new RxNavigationPage()
        {
            new RxContentPage()
            {

            }
            .Title("Component With Children")
        };
    }
}
```

This should show a page with a title; let's now create a component for our grid (call it `WrapGrid`)

```csharp
public class WrapGrid : RxComponent
{
    public override VisualNode Render()
    {
    }
}
```

Every `RxComponent` can access its children using Children() method (like `{this.props.children}` in react)

```csharp
public class WrapGrid : RxComponent
{
    public override VisualNode Render()
    {
        return new RxGrid()
        {
            Children().ToArray()
        };
    }
}

```

Now let's add a `ColumnCount` property and a simple logic to arrange and wraps any children passed

```csharp
public class WrapGrid : RxComponent
{
    private int _columnCount = 4;
    public WrapGrid ColumnCount(int columnCount)
    {
        _columnCount = columnCount;
        return this;
    }

    public override VisualNode Render()
    {
        int rowIndex = 0, colIndex = 0;

        int rowCount = Math.DivRem(Children().Count, _columnCount, out var divRes);
        if (divRes > 0)
            rowCount++;

        return new RxGrid(
            Enumerable.Range(1, rowCount).Select(_ => new RowDefinition() { Height = GridLength.Auto }),
            Enumerable.Range(1, _columnCount).Select(_ => new ColumnDefinition()))
        {
            Children().Select(child =>
            {
                child.GridRow(rowIndex);
                child.GridColumn(colIndex);
                
                colIndex++;
                if (colIndex == _columnCount)
                {
                    colIndex = 0;
                    rowIndex++;
                }

                return child;
            }).ToArray()
        };
    }
}
```

Finally we just need to create the component from the page:

```csharp
public class PageState : IState
{
    public int ColumnCount { get; set; } = 1;

    public int ItemCount { get; set; } = 3;
}

public class PageComponent : RxComponent<PageState>
{
    public override VisualNode Render()
    {
        return new RxNavigationPage()
        {
            new RxContentPage()
            {
                new RxStackLayout()
                { 
                    new RxLabel($"Columns {State.ColumnCount}")
                        .FontSize(Xamarin.Forms.NamedSize.Large),
                    new RxStepper()
                        .Minimum(1)
                        .Maximum(10)
                        .Increment(1)
                        .Value(State.ColumnCount)
                        .OnValueChanged(_=> SetState(s => s.ColumnCount = (int)_.NewValue)),
                    new RxLabel($"Items {State.ItemCount}")
                        .FontSize(Xamarin.Forms.NamedSize.Large),
                    new RxStepper()
                        .Minimum(1)
                        .Maximum(20)
                        .Increment(1)
                        .Value(State.ItemCount)
                        .OnValueChanged(_=> SetState(s => s.ItemCount = (int)_.NewValue)),

                    new WrapGrid()
                    { 
                        Enumerable.Range(1, State.ItemCount)
                            .Select(_=> new RxButton($"Item {_}"))
                            .ToArray()
                    }
                    .ColumnCount(State.ColumnCount)                            
                }
                .Padding(10)
                .WithVerticalOrientation()
            }
            .Title("Component With Children")
        };
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://adospace.gitbook.io/reactorui/guide/components-with-a-state/component-with-children.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
