### Start Platform Tests
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/contribute/01-development/04-author-patch.md
Command to start the platform tests development server.
```bash
npm run dev -w platform-tests
```
--------------------------------
### Run Documentation Website Locally
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/contribute/01-development/04-author-patch.md
Command to start the documentation website development server.
```bash
npm run dev -w website
```
--------------------------------
### Run Development Server
Source: https://github.com/react/react-strict-dom/blob/main/apps/nextjs-app/README.md
Execute this command to start the Next.js development server. Open http://localhost:3000 in your browser to view the application.
```bash
npm run dev
```
--------------------------------
### Install Dependencies for Vite 7
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/learn/environment-setup/03-vite.md
Install necessary packages for Vite 7 setup, including vite-plugin-babel and vite-tsconfig-paths.
```bash
npm install vite-plugin-babel vite-tsconfig-paths
```
--------------------------------
### Install Web Peer Dependencies
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/learn/01-installation.md
For web support, ensure these React and ReactDOM packages are installed as peer dependencies.
```bash
npm install react react-dom
```
--------------------------------
### Install vite-plugin-babel
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/learn/environment-setup/03-vite.md
Install the necessary plugin for Vite 8 to enable Babel transformations.
```bash
npm install vite-plugin-babel
```
--------------------------------
### Install React Strict DOM
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/learn/01-installation.md
Run this command to install the main React Strict DOM package in your React project.
```bash
npm install react-strict-dom
```
--------------------------------
### Complete React Strict DOM Example with Theming
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/static/llms.txt
Demonstrates a complete React Strict DOM component using `css.defineVars` for theming and `css.create` for component styles. Includes responsive styles and pseudo-states.
```jsx
// tokens.css.js
import { css } from 'react-strict-dom';
export const colors = css.defineVars({
primary: { default: 'blue', '@media (prefers-color-scheme: dark)': 'lightblue' },
text: { default: 'black', '@media (prefers-color-scheme: dark)': 'white' },
background: { default: 'white', '@media (prefers-color-scheme: dark)': '#222' }
});
// Component.js
import { html, css } from 'react-strict-dom';
import { colors } from './tokens.css.js';
const styles = css.create({
container: {
padding: 16,
backgroundColor: colors.background
},
title: {
fontSize: 24,
fontWeight: 'bold',
color: colors.text,
marginBottom: 16
},
button: {
padding: 12,
backgroundColor: {
default: colors.primary,
':hover': 'darkblue',
':active': 'navy'
},
color: 'white',
borderRadius: 8,
borderWidth: 0
}
});
function Card({ title, onPress, style }) {
return (
{title}
Click me
);
}
```
--------------------------------
### Verify Node.js PATH
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/contribute/01-development/01-install-node.md
Confirm that the installed Node.js executable is accessible in your system's PATH.
```bash
$ which node
/usr/local/bin/node
```
--------------------------------
### Check Node.js Version
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/contribute/01-development/01-install-node.md
Verify your current Node.js installation version. Ensure it meets the `>=20.11` requirement.
```bash
$ node --version
v20.17.0
```
--------------------------------
### Check npm Version
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/contribute/01-development/01-install-node.md
Verify your current npm installation version. Ensure it meets the `>=10` requirement.
```bash
$ npm --version
10.8.2
```
--------------------------------
### Generate Static CSS with Babel Preset
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/api/01-babel/01-preset.md
Illustrative example showing how to collect style rules during Babel transformation and then generate a static CSS string using the preset's generateStyles method. This is a web-only feature.
```js
import reactStrictBabelPreset from 'react-strict-dom/babel-preset';
const styleRules = {};
function transform() {
const { code, metadata } = await babel.transformAsync(sourceCode, babelConfig);
if (metadata.stylex != null && metadata.stylex.length > 0) {
// collect styles from files
styleRules[id] = metadata.stylex;
}
// ...
}
function bundle() {
const rules = Object.values(styleRules).flat();
// generate CSS string from all collected styles
const css = reactStrictBabelPreset.generateStyles(rules);
// ...write css to file
}
```
--------------------------------
### Install Native Peer Dependencies
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/learn/01-installation.md
For native support, ensure these React and React Native packages are installed as peer dependencies.
```bash
npm install react react-native
```
--------------------------------
### HTML Input Element Example
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/static/llms.txt
Renders an HTML input element for text entry. Shows how to manage input values with onChange and set attributes like type, value, placeholder, and maxLength.
```jsx
// Input
setText(e.target.value)} placeholder="Text" maxLength={100} />
```
--------------------------------
### HTML Image Element Example
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/static/llms.txt
Renders an HTML image element. Demonstrates setting the src, alt text, width, and height attributes for an image.
```jsx
// Image
```
--------------------------------
### HTML Link Element Example
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/static/llms.txt
Renders an HTML anchor (link) element. Shows how to specify the destination URL using the href attribute.
```jsx
// Link
Link
```
--------------------------------
### HTML Button Element Example
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/static/llms.txt
Renders a basic HTML button element using React Strict DOM. Demonstrates the use of the html.button tag and common props like disabled and onClick.
```jsx
// Button
{}}>Click
```
--------------------------------
### Create and Apply a Theme
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/api/02-css/02-createTheme.md
Demonstrates how to create theme objects for colors and spacing, combine them, and apply them to a div element.
```jsx
import { css } from 'react-strict-dom';
import { colors, spacing } from './vars.css.js';
const themeColors = css.createTheme(colors, {
accent: 'red',
textPrimary: 'black',
textSecondary: 'brown',
});
const themeSpacing = css.createTheme(spacing, {
small: '0.25rem',
large: '0.5rem'
});
const theme = [ themeColors, themeSpacing ];
const Theme = (props) =>
```
--------------------------------
### Styling with Media Queries
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/static/llms.txt
Demonstrates how to apply responsive styles using media queries within the css.create() object. Supports dimension queries and color scheme preferences.
```jsx
const styles = css.create({
container: {
width: {
default: 320,
'@media (min-width: 768px)': 600,
'@media (min-width: 1024px)': 800
},
color: {
default: 'black',
'@media (prefers-color-scheme: dark)': 'white'
}
}
});
```
--------------------------------
### css overview
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/api/index.md
An overview of working with styles.
```APIDOC
## css overview
### Description
An overview of working with styles.
### Endpoint
/api/css/
```
--------------------------------
### css.createTheme
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/api/index.md
How to create themes.
```APIDOC
## css.createTheme
### Description
How to create themes.
### Endpoint
/api/css/createTheme
```
--------------------------------
### css.create
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/api/index.md
How to create styles.
```APIDOC
## css.create
### Description
How to create styles.
### Endpoint
/api/css/create
```
--------------------------------
### Create Theme with Overrides
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/api/02-css/02-createTheme.md
Illustrates creating a theme object by providing the defined variables and an object of overrides.
```js
import { colors } from './vars.css.js';
const themeColors = css.createTheme(colors, {
accent: 'red',
textPrimary: 'black',
textSecondary: 'brown',
})
```
--------------------------------
### html overview
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/api/index.md
An overview of working with components.
```APIDOC
## html overview
### Description
An overview of working with components.
### Endpoint
/api/html/
```
--------------------------------
### Run Performance Benchmarks
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/contribute/01-development/04-author-patch.md
Commands to run performance and size benchmarks.
```bash
npm run perf -w benchmarks
```
```bash
npm run size -w benchmarks
```
--------------------------------
### Configure Metro Bundler for Expo
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/learn/environment-setup/01-expo.md
This Metro configuration is for Expo projects and ensures support for package exports in React Native. It uses `expo/metro-config` to get default settings.
```javascript
// Learn more https://docs.expo.dev/guides/monorepos
const { getDefaultConfig } = require('expo/metro-config');
// Find the project and workspace directories
const projectRoot = __dirname;
const config = getDefaultConfig(projectRoot);
module.exports = config;
```
--------------------------------
### Define Variables for Theming
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/api/02-css/02-createTheme.md
Shows how to define style variables using css.defineVars, which can later be overridden by createTheme.
```js
export const colors = css.defineVars({
accent: 'blue',
textPrimary: 'black',
textSecondary: '#333',
});
```
--------------------------------
### Configure Vite 7 for React Strict DOM
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/docs/learn/environment-setup/03-vite.md
Configure vite.config.ts for Vite 7, including plugins, resolve extensions, and optimizeDeps. This setup uses vite-tsconfig-paths and configures viteReact with Babel.
```typescript
import { defineConfig } from "vite";
import tsConfigPaths from "vite-tsconfig-paths";
import viteReact from "@vitejs/plugin-react";
import viteBabel from "vite-plugin-babel";
const webOnlyExtensions = [".web.js", ".web.jsx", ".web.ts", ".web.tsx"];
export default defineConfig(() => ({
plugins: [
tsConfigPaths(),
viteReact({
// plugin-react@5 applies the preset to your source through Babel.
babel: { configFile: true },
}),
// No include needed: viteReact handles source, and the default
// include (/".jsx?$/) covers node_modules that ship compiled UI.
viteBabel(),
],
resolve: {
extensions: [
...webOnlyExtensions,
".mjs",
".js",
".mts",
".ts",
".jsx",
".tsx",
".json",
],
},
}));
```
--------------------------------
### Basic Styling with css.create()
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/static/llms.txt
Demonstrates how to apply basic styles to an HTML element using the css.create() function and the style prop in React Strict DOM. Styles are defined in a JavaScript object.
```jsx
import { css, html } from 'react-strict-dom';
const styles = css.create({
container: {
padding: 16,
backgroundColor: 'white',
borderRadius: 8
}
});
Content
```
--------------------------------
### Fixing Props for HTML Elements in RSD
Source: https://github.com/react/react-strict-dom/blob/main/packages/website/static/llms.txt
Adjust HTML element props for compatibility with React Strict DOM. For example, change `htmlFor` to `for` and `role="presentation"` to `role="none"`.
```jsx
// Before: