# Closed Components URL: https://ark-ui.com/docs/guides/closed-components Source: https://raw.githubusercontent.com/chakra-ui/ark/refs/heads/main/website/src/content/pages/guides/closed-components.mdx Learn how to create reusable components using the example of an avatar --- ## Motivation Writing a few lines of code every time you need a simple `Avatar` is tedious. Creating a dedicated component encapsulates logic, simplifies the API, ensures consistent usage, and maintains clean code. This approach enhances reusability, making the component easier to maintain and test. Here's an example of an `Avatar` component that can be used consistently across your application: **Example: closed** #### React ```tsx import { Avatar as ArkAvatar } from '@ark-ui/react/avatar' import { UserIcon } from 'lucide-react' import { forwardRef } from 'react' export interface AvatarProps extends ArkAvatar.RootProps { name?: string | undefined src?: string | undefined } export const Avatar = forwardRef((props, ref) => { const { name, src, ...rootProps } = props return ( {getInitials(name) || } ) }) const getInitials = (name = '') => name .split(' ') .map((part) => part[0]) .slice(0, 2) .join('') .toUpperCase() ``` #### Solid ```tsx import { Avatar as ArkAvatar } from '@ark-ui/solid/avatar' import { UserIcon } from 'lucide-solid' import { Show, splitProps } from 'solid-js' export interface AvatarProps extends ArkAvatar.RootProps { name?: string src?: string } export const Avatar = (props: AvatarProps) => { const [localProps, rootProps] = splitProps(props, ['name', 'src']) return ( }> {getInitials(localProps.name)} ) } const getInitials = (name = '') => name .split(' ') .map((part) => part[0]) .splice(0, 2) .join('') .toUpperCase() ``` #### Vue ```vue ``` #### Svelte ```svelte {#if initials} {initials} {:else} {/if} ``` ## Usage To use the `Avatar` component, pass the `name` and `src` props as shown below: ```jsx ```