Skip to content

Hooks

The hooks behind the components, for building controls and behaviors of your own.

The components share a few hooks: for copying to the clipboard, reacting to scrolling, keyboard shortcuts, loading suggestions, and connecting a control to a Field. Each hook is its own registry item. To build something the components don't cover, add one the same way you add a component:

The shadcn CLI copies the hook into your project's @/hooks, where it's yours to change. Adding a component also adds the hooks it uses, so you may have some already.

All hooks

  • useAsyncSuggestions

    Loads suggestions for typed text after a pause, and reports why one is highlighted.

  • useCopyToClipboard

    Copies text to the clipboard and tracks whether it worked.

  • useField

    Connects a custom control to the Field around it: its labels, description, error and state.

  • useShortcut

    Runs a callback on a keyboard shortcut and formats the shortcut for the person's platform.