Ark Logo
Closed components

Closed Components

Learn how to create reusable components using the example of an avatar


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:

import { UserIcon } from 'lucide-solid'
import { Show, splitProps } from 'solid-js'
import { Avatar as ArkAvatar } from '@ark-ui/solid'

export interface AvatarProps extends ArkAvatar.RootProps {
  name?: string
  src?: string

export const Avatar = (props: AvatarProps) => {
  const [localProps, rootProps] = splitProps(props, ['name', 'src'])

  return (
    <ArkAvatar.Root {...rootProps}>
        <Show when={} fallback={<UserIcon />}>
      <ArkAvatar.Image src={localProps.src} alt={} />

const getInitials = (name = '') =>
    .split(' ')
    .map((part) => part[0])
    .splice(0, 2)


To use the Avatar component, pass the name and src props as shown below:

<Avatar name="Christian" src="" />