# Component State URL: https://ark-ui.com/docs/guides/component-state Source: https://raw.githubusercontent.com/chakra-ui/ark/refs/heads/main/website/src/content/pages/guides/component-state.mdx Learn how to manage component state using Context and Provider components. --- ## Context Components Context components expose state and functions to child components. In this example, `Avatar.Fallback` renders based on `loaded` state. **Example: context** #### React ```tsx import { Avatar } from '@ark-ui/react/avatar' import styles from 'styles/avatar.module.css' export const Context = () => ( {(avatar) => {avatar.loaded ? 'PA' : 'Loading'}} ) ``` #### Solid ```tsx import { Avatar } from '@ark-ui/solid/avatar' import styles from 'styles/avatar.module.css' export const Context = () => ( {(avatar) => {avatar().loaded ? 'PA' : 'Loading'}} ) ``` #### Vue ```vue ``` #### Svelte ```svelte {#snippet api(avatar)} {#if avatar().loaded}

PA

{:else}

Loading

{/if}
{/snippet}
``` > **Good to know (RSC)**: Due to the usage of render prop, you might need to add the `'use client'` directive at the top > of your file when using React Server Components. ## Provider Components Provider components can help coordinate state and behavior between multiple components, enabling interactions that aren't possible with `Context` components alone. They are used alongside component hooks. **Example: root-provider** #### React ```tsx import { Accordion, useAccordion } from '@ark-ui/react/accordion' import { ChevronDownIcon } from 'lucide-react' import styles from 'styles/accordion.module.css' export const RootProvider = () => { const accordion = useAccordion({ multiple: true, defaultValue: ['ark-ui'], }) return ( <> {items.map((item) => ( {item.title}
{item.content}
))}
) } const items = [ { value: 'ark-ui', title: 'What is Ark UI?', content: 'A headless component library for building accessible web apps.', }, { value: 'getting-started', title: 'How to get started?', content: 'Install the package and import the components you need.', }, { value: 'maintainers', title: 'Who maintains this project?', content: 'Ark UI is maintained by the Chakra UI team.', }, ] ``` #### Solid ```tsx import { Accordion, useAccordion } from '@ark-ui/solid/accordion' import { ChevronDownIcon } from 'lucide-solid' import { Index } from 'solid-js' import styles from 'styles/accordion.module.css' export const RootProvider = () => { const accordion = useAccordion({ multiple: true, defaultValue: ['ark-ui'], }) return ( <> {(item) => ( {item().title}
{item().content}
)}
) } const items = [ { value: 'ark-ui', title: 'What is Ark UI?', content: 'A headless component library for building accessible web apps.', }, { value: 'getting-started', title: 'How to get started?', content: 'Install the package and import the components you need.', }, { value: 'maintainers', title: 'Who maintains this project?', content: 'Ark UI is maintained by the Chakra UI team.', }, ] ``` #### Vue ```vue ``` #### Svelte ```svelte
{#each items as item (item.value)} {item.title}
{item.content}
{/each}
``` > When using the `RootProvider` component, you don't need to use the `Root` component. See more in [Examples](/examples/popover-selection).