# 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' export const Context = () => ( {(avatar) => {avatar.loaded ? 'PA' : 'Loading'}} ) ``` #### Solid ```tsx import { Avatar } from '@ark-ui/solid/avatar' 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' export const RootProvider = () => { const accordion = useAccordion({ multiple: true, defaultValue: ['React'], }) return ( <> {['React', 'Solid', 'Vue', 'Svelte'].map((item) => ( What is {item}? {item} is a JavaScript library for building user interfaces. ))} ) } ``` #### Solid ```tsx import { Accordion, useAccordion } from '@ark-ui/solid/accordion' import { ChevronDownIcon } from 'lucide-solid' import { Index } from 'solid-js' export const RootProvider = () => { const accordion = useAccordion({ multiple: true, defaultValue: ['React'], }) return ( <> {(item) => ( What is {item()}? {item()} is a JavaScript library for building user interfaces. )} ) } ``` #### Vue ```vue ``` #### Svelte ```svelte
Open items: {JSON.stringify(accordion().value)}
{#each ['React', 'Solid', 'Vue', 'Svelte'] as item (item)} What is {item}? {item} is a JavaScript library for building user interfaces. {/each}
``` > When using the `RootProvider` component, you don't need to use the `Root` component. See more in [Examples](/examples/popover-selection).