# MappedComponents

Learn how to reference component IDs and the component content map.

This interface holds the component ID union and the indexed component map, generated by the [CLI](/reference/cli/type-generation) in the `Croct\Content` namespace.

## Example

Supposing you have a component named `card` with versions 1 and 2, `ComponentId` is the union of every valid ID (`'card'`, `'card@latest'`, `'card@1'`, and `'card@2'`), and `ComponentMap` maps each ID to its content type.

With a `@template` bound to `ComponentId`, a handler can keep the content type in sync with the ID it receives. Import the types with [`@phpstan-import-type`](https://phpstan.org/writing-php-code/phpdoc-types#local-type-aliases):

```php
<?php
/**
 * @phpstan-import-type ComponentId from \Croct\Content\MappedComponents
 * @phpstan-import-type ComponentMap from \Croct\Content\MappedComponents
 */
final class Renderer
{
    /**
     * @template T of ComponentId
     *
     * @param T $componentId
     * @param ComponentMap[T] $content
     */
    public function render(string $componentId, array $content): void
    {
        // Render the content for the component.
    }
}
```

Indexing the map requires PHPStan. Psalm supports `ComponentId` through [`@psalm-import-type`](https://psalm.dev/docs/annotating_code/supported_annotations/#psalm-import-type) but cannot index the map, so type the content with a [named type](/reference/sdk/php/api/types/components) instead.
