# 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. --- Need to access a component's state? You have three options: | Approach | When to use it | | ------------------------------- | --------------------------------------------- | | `Component.Context` | Quick inline access via render props | | `use*Context` hooks | Build custom child components that read state | | `useComponent` + `RootProvider` | Control the component from outside | ## Context Components Use `Component.Context` to access state inline via render props. Here, `Avatar.Fallback` reads the `loaded` state to show different content: > **Good to know (RSC)**: The render prop pattern requires the `'use client'` directive when using React Server > Components. ## Context Hooks Every component exports a `use*Context` hook (like `useDialogContext` or `useMenuContext`). Call it from any child component to access state and methods—no render props needed. ```tsx import { Dialog, useDialogContext } from '@ark-ui/react/dialog' function CustomCloseButton() { const dialog = useDialogContext() return } export const Demo = () => ( Open ) ``` The hook returns the same API as `Component.Context`, just without the nesting. ## Provider Components Need to control a component from outside its tree? Use a `useComponent` hook (like `useDialog`) with `RootProvider`. > When you use `RootProvider`, skip the `Root` component—you don't need both. ## Choosing the Right Approach - **`Component.Context`** — Quick inline access for conditional rendering - **`use*Context` hooks** — Build reusable child components that need parent state - **`useComponent` + `RootProvider`** — Trigger actions from outside (like opening a dialog from a menu item)