Standardized process for working with dynamic styling in react, specifically how to pass react variables to css and use them inside css files.
Standardize how dynamic React variables are passed to CSS to ensure flexibility, maintainability, and type safety.
style prop on an element or component.Pass dynamic values as CSS variables rather than applying CSS properties directly. This keeps styling logic in CSS and allows for easy overrides.
❌ Bad:
<div style={{ color: someValue }}>...</div>
✅ Good:
Use the createStyles helper to avoid TypeScript errors when passing custom CSS variables:
const dynamicStyles = createStyles({
"--my-component-color": someValue
});
<div style={dynamicStyles} className="my-class">...</div>
Pass the minimum raw value to CSS and perform calculations (like calc()) inside the stylesheet.
❌ Bad:
createStyles({ "--my-component-width": `calc(100% - ${width}px)` })
✅ Good:
createStyles({ "--my-component-width": `${width}px` })
.my-class {
width: calc(100% - var(--my-component-width));
}
Prefix CSS variables with the component name to prevent global naming collisions.
❌ Bad: --width
✅ Good: --my-component-width
Always define a default value for the CSS variable in the stylesheet rather than relying on var(--var-name, fallback) everywhere it's used.
✅ Good:
.my-class {
/* Default fallback */
--my-component-color: #000;
color: var(--my-component-color);
}
npx skills add ViewableGravy/react_dynamic-styling下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer