Performance: CSS-in-JS considerations
MEDIUM IMPACT
This affects page load speed and rendering performance by how styles are generated and applied in the browser.
import { css } from '@emotion/react'; const buttonStyle = css` color: red; font-size: 1rem; `; export default function Page() { return <button css={buttonStyle}>Click me</button>; }
import styled from 'styled-components'; const Button = styled.button` color: red; font-size: 1rem; `; export default function Page() { return <Button>Click me</Button>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Runtime CSS-in-JS (styled-components) | Low | 1 per style injection | Medium due to delayed styles | [X] Bad |
| Static CSS extraction (Emotion SSR) | Low | Single reflow | Low paint cost | [OK] Good |