react-strict-dom
Set up react-strict-dom with Babel, PostCSS, and CSS-wrapped HTML components for universal Expo apps
Install
mkdir -p .claude/skills/react-strict-dom && curl -L -o skill.zip "https://mcp.directory/api/skills/download/4966" && unzip -o skill.zip -d .claude/skills/react-strict-dom && rm skill.zipInstalls to .claude/skills/react-strict-dom
About this skill
React Strict DOM Setup for Expo
This guide covers setting up react-strict-dom in an Expo project with Tailwind CSS v4 and react-native-css for universal app development.
Overview
react-strict-dom provides a subset of HTML/CSS that works identically across web and native platforms. This setup includes:
- Babel preset - Transforms react-strict-dom components for each platform
- PostCSS plugin - Processes styles for web builds
- CSS directive - Enables react-strict-dom styles in global CSS
- HTML wrapper components - CSS-wrapped primitives with Tailwind className support
Installation
Install react-strict-dom using bun:
bun install react-strict-dom@0.0.54
Note: Version 0.0.55 has a broken dependency (
postcss-react-strict-dom@0.0.55doesn't exist). Use 0.0.54 until this is resolved.
Babel Configuration
Create or update babel.config.js in the project root:
const reactStrictPreset = require("react-strict-dom/babel-preset");
function getPlatform(caller) {
return caller && caller.platform;
}
function getIsDev(caller) {
if (caller?.isDev != null) return caller.isDev;
// https://babeljs.io/docs/options#envname
return (
process.env.BABEL_ENV === "development" ||
process.env.NODE_ENV === "development"
);
}
module.exports = function (api) {
//api.cache(true);
const platform = api.caller(getPlatform);
const dev = api.caller(getIsDev);
return {
presets: [
"babel-preset-expo",
[reactStrictPreset, { debug: true, dev, platform }],
],
};
};
Configuration Options
debug: true- Enables debug output during developmentdev- Automatically detected from environmentplatform- Passed by Metro/bundler for platform-specific transforms
PostCSS Configuration
Update postcss.config.mjs to include the react-strict-dom plugin:
export default {
plugins: {
"@tailwindcss/postcss": {},
"react-strict-dom/postcss-plugin": {
include: ["src/**/*.{js,jsx,mjs,ts,tsx}"],
},
},
};
The include option specifies which files to process for react-strict-dom styles.
Global CSS Directive
Add the @react-strict-dom directive at the top of your global CSS file (e.g., src/global.css):
@react-strict-dom;
@import "tailwindcss/theme.css" layer(theme);
@import "tailwindcss/preflight.css" layer(base);
@import "tailwindcss/utilities.css";
/* ... rest of your styles */
This directive must be the first rule in the file for react-strict-dom styles to work correctly.
HTML Components with Tailwind Support
Create CSS-wrapped HTML components that support Tailwind className at src/html/index.tsx:
import { useCssElement } from "react-native-css";
import React from "react";
import { html as rsd } from "react-strict-dom";
import { StyleSheet } from "react-native";
function createCssComponent<T extends keyof typeof rsd>(
elementName: T,
displayName?: string
) {
type Props = React.ComponentProps<(typeof rsd)[T]> & {
className?: string;
};
let Component: (props: Props) => React.ReactElement;
if (process.env.EXPO_OS === "web") {
Component = (props: Props) => {
// eslint-disable-next-line import/namespace
return useCssElement(rsd[elementName], props, {
// @ts-expect-error
className: "style",
});
};
} else {
Component = ({ style, ...props }: Props) => {
const normal = props as any;
if (style) {
normal.style = normalizeStyle(style);
}
return useCssElement(
// eslint-disable-next-line import/namespace
rsd[elementName],
normal,
{
// @ts-expect-error
className: "style",
}
);
};
}
(Component as any).displayName = displayName || `CSS(${elementName})`;
return Component;
}
function normalizeStyle(style: any) {
if (!style) return style;
const flat = StyleSheet.flatten(style);
if (flat.backgroundImage) {
flat.experimental_backgroundImage = flat.backgroundImage;
delete flat.backgroundImage;
}
return flat;
}
export const html = {
button: createCssComponent("button"),
div: createCssComponent("div"),
h1: createCssComponent("h1"),
h2: createCssComponent("h2"),
h3: createCssComponent("h3"),
h4: createCssComponent("h4"),
h5: createCssComponent("h5"),
h6: createCssComponent("h6"),
p: createCssComponent("p"),
span: createCssComponent("span"),
img: createCssComponent("img"),
input: createCssComponent("input"),
textarea: createCssComponent("textarea"),
a: createCssComponent("a"),
ul: createCssComponent("ul"),
ol: createCssComponent("ol"),
li: createCssComponent("li"),
nav: createCssComponent("nav"),
header: createCssComponent("header"),
footer: createCssComponent("footer"),
main: createCssComponent("main"),
section: createCssComponent("section"),
article: createCssComponent("article"),
aside: createCssComponent("aside"),
label: createCssComponent("label"),
form: createCssComponent("form"),
i: createCssComponent("i"),
b: createCssComponent("b"),
strong: createCssComponent("strong"),
em: createCssComponent("em"),
code: createCssComponent("code"),
pre: createCssComponent("pre"),
blockquote: createCssComponent("blockquote"),
hr: createCssComponent("hr"),
};
Usage
Import and use the HTML components with Tailwind classes:
import { html } from "@/html";
export function MyComponent() {
return (
<html.div className="flex flex-col gap-4 p-4 bg-sf-bg">
<html.h1 className="text-2xl font-bold text-sf-text">
Hello World
</html.h1>
<html.p className="text-sf-text-2">
This works on both web and native!
</html.p>
<html.button className="px-4 py-2 bg-sf-blue text-white rounded-lg">
Click me
</html.button>
</html.div>
);
}
How It Works
Web
On web, react-strict-dom renders actual HTML elements (<div>, <button>, etc.) with the PostCSS plugin processing styles. The useCssElement wrapper enables Tailwind className support.
Native (iOS/Android)
On native, react-strict-dom transforms HTML elements into equivalent React Native components:
<div>→<View><span>,<p>→<Text><img>→<Image>- etc.
The Babel preset handles these transformations at build time.
Style Normalization
The normalizeStyle function handles platform-specific style differences:
- Flattens style arrays using
StyleSheet.flatten() - Converts
backgroundImagetoexperimental_backgroundImagefor native compatibility
Benefits
- Semantic HTML: Write semantic HTML that works everywhere
- Better SEO: Real HTML elements on web
- Accessibility: Native HTML semantics for screen readers
- Tailwind Integration: Full className support with react-native-css
- Type Safety: Full TypeScript support with proper component props
- Platform Optimizations: Platform-specific transforms at build time
Troubleshooting
"postcss-react-strict-dom version not found"
Use react-strict-dom@0.0.54 instead of the latest version. Version 0.0.55 has a missing dependency.
Styles not applying on native
Ensure the @react-strict-dom directive is at the top of your global CSS file.
TypeScript errors with displayName
Use type assertions when setting displayName:
(Component as any).displayName = displayName;
backgroundImage not working on native
The normalizeStyle function handles this automatically by mapping to experimental_backgroundImage.
More by EvanBacon
View all skills by EvanBacon →You might also like
flutter-development
aj-geddes
Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.
drawio-diagrams-enhanced
jgtolentino
Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.
ui-ux-pro-max
nextlevelbuilder
"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."
godot
bfollington
This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.
nano-banana-pro
garg-aayush
Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.
fastapi-templates
wshobson
Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.
Stay ahead of the MCP ecosystem
Get weekly updates on new skills and servers.