Skip to main content

AI Assistants

AI assistants write much better code with react-better-html when they know its conventions - which components exist, that styles are passed as props, which subcomponents to use and which plugins a feature needs. The documentation is published in formats made for them, and you can add a ready rule to your editor.

Documentation for AI​

The documentation follows the llms.txt standard:

  • llms.txt - a short overview of the library, the rules for writing code with it and a link to every page
  • llms-full.txt - the whole documentation in one file. Useful to paste into a chat or to add as a documentation source in your editor
  • Markdown pages - every docs page is available as clean markdown by adding .md to its URL, for example /docs/components/button.md
tip

Most AI editors can index documentation from a URL (for example Cursor @Docs → Add new doc). Add https://krissvv.github.io/react-better-html/llms-full.txt there and reference it in your prompts.

Editor rule​

Save the rule below in your project and the assistant will follow the library conventions every time it writes code with it. The rule contains the most important conventions and tells the assistant where to read the documentation for everything else.

Pick your editor - the header at the top of each rule makes it load only when it is needed instead of in every conversation.

Save as .cursor/rules/react-better-html.mdc. Cursor attaches it when the task is about the library, or you can mention it with @react-better-html in the chat.

.cursor/rules/react-better-html.mdc
---
description: Rules for building UI with the react-better-html component library. Use when writing or editing React components that import from react-better-html.
alwaysApply: false
---

# react-better-html

A React 19 component library that stays as close to plain HTML as possible. Every component accepts all of its HTML element's attributes plus every CSS property as a prop (with a `Hover` variant), and common variations are exposed as dot subcomponents like `Div.row` or `Button.secondary`. It is built on styled-components and themed through a single `<BetterHtmlProvider>`.

Use these rules when writing or editing code that imports from `react-better-html`. When a component, prop or function is not covered here, read the documentation instead of guessing:

- Index of all pages: https://krissvv.github.io/react-better-html/llms.txt
- The whole documentation in one file: https://krissvv.github.io/react-better-html/llms-full.txt
- Any docs page as markdown: add `.md` to its URL (for example https://krissvv.github.io/react-better-html/docs/components/button.md)

## Rules

- Install with `npm install react-better-html`. Everything (components, hooks, functions and types) is imported from `"react-better-html"`.
- Wrap the app once in `<BetterHtmlProvider>`. Hooks, controls and most components throw or render incorrectly without it. Plugins are passed with `<BetterHtmlProvider plugins={[...]}>` and must never change at runtime.
- Use `<Div>` and `<Text>` instead of raw `<div>`, `<p>`, `<h1>`, etc. Change the rendered tag with `as` (`<Text as="h1">`, `<Div as="main">`). Use `Div.row`, `Div.column` and `Div.grid` instead of writing `display: flex` by hand.
- Style with props, not `style` or CSS files: `<Div padding={16} backgroundColor="#fff" borderRadius={10}>`. Numbers are pixels. Every CSS prop has a hover version with the `Hover` suffix: `backgroundColorHover`, `colorHover`, `filterHover`.
- Take spacing and colors from the theme instead of hardcoding: `const theme = useTheme();` then `theme.styles.space` (16), `theme.styles.gap` (8), `theme.styles.borderRadius` (10), `theme.colors.primary`, `theme.colors.textPrimary`, `theme.colors.textSecondary`, `theme.colors.backgroundContent`, `theme.colors.border`. Colors follow the current light or dark theme automatically.
- Subcomponents are presets: `Button.secondary`, `Button.destructive`, `Button.text`, `Button.icon`, `Button.upload`, `Text.unknown`, `Text.oneLine`, `Div.box`, `InputField.email`, `InputField.password`, `InputField.search`, `InputField.date`, `Modal.confirmation`, `Modal.destructive`, `Tabs.content`, `Tooltip.item` and more. `ToggleInput` and `Divider` can only be used as subcomponents (`ToggleInput.checkbox`, `ToggleInput.radiobutton`, `ToggleInput.switch`, `Divider.horizontal`, `Divider.vertical`).
- Prefer the value-based callbacks: `onChangeValue={(value) => ...}` on `InputField`, `onChange={(value) => ...}` on `Dropdown`, `onChange={(checked, value) => ...}` on `ToggleInput`, and `value` + `onClickWithValue={(value) => ...}` on `Div`, `Button` and `Chip`.
- Imperative components are controlled with a ref: `const modalRef = useRef<ModalRef>(null); modalRef.current?.open();` (also `TooltipRef`, `TabsRef`, `FoldableRef`, `TableRef`).
- Build forms with `useForm({ defaultValues, requiredFields, validate, onSubmit })` and `<Form form={form} submitButtonText="Save">`, then spread `form.getInputFieldProps("field")`, `form.getDropdownFieldProps(...)`, `form.getCheckboxProps(...)`, `form.getRadioButtonProps(field, value)`, `form.getSwitchProps(...)` or `form.getTextAreaProps(...)` onto the fields. Use `FormRow` to put two fields on one line.
- Icon names (`<Icon name>`, `icon` props) must exist in `config.icons` and asset names (`<Image name>`, `image` props) in `config.assets`. Built-in icons: `XMark`, `uploadCloud`, `trash`, `chevronDown`, `chevronLeft`, `chevronRight`, `doubleChevronLeft`, `doubleChevronRight`, `eye`, `eyeDashed`, `magnifyingGlass`, `check`, `infoI`, `warningTriangle`, `filter`. The `logo` asset is an empty placeholder meant to be overridden. Use `src` for image URLs.
- Global loading states use named loaders: `useLoader("name")` to read, `useLoaderControls()` or `loaderControls` to start and stop, `loaderName="name"` on `Button`.
- Alerts need `alertsPlugin()` and are created with `useAlertControls().createAlert({ type, title, message })` or `alertControls.createAlert(...)`. `Modal` `name` and `Tabs` URL sync need `reactRouterDomPlugin()`. `generateLocalStorage` needs `localStoragePlugin()`.
- Make layouts responsive with `useMediaQuery()` (`mediaQuery.size600`, `size900`, `size1000`, ... are `true` at or below that width) combined with `invertFlexDirection` on `Div.row` / `Div.column`.
- Default component styles can be set app-wide in `config.components` (for example `components.button.style.default`). Set `components.button.tagReplacement.linkComponent` to the router `Link` so `Button href` and `SideMenu` items navigate client-side.
note

The rule is generated from the latest documentation. Copy it again after updating the library to get the newest conventions.