It's Just JavaScript

Since immutable styles is just JavaScript it gets the niceties of CSS pre-processors for free. Leveraging everyday JavaScript enables variables, detached rulesets, pre-processor mixins, and theming with little to no extra cost.

Variables

const brandColor = 'plum';

// usage:

<nav>
  background: { brandColor };
</nav>

Detached Rulesets

const fontMedium = `
  font-family: 'Open Sans', sans-serif;
  font-weight: 600;
  font-size: 2.1rem;
`;

// usage:

<h1>
  { fontMedium }
</h1>

Pre-processor Mixins

You can create your own:

Or use a library such as polished-styles:

Not to be confused with immutable mixins.

Themes

Server-side

Compiling immutable styles server-side – and of course infrastructure permitting – would enable futher functionality, such as generating CSS specific to:

  • ⚗️ Experiments (AB testing)

  • 🎌 Locale

  • 📱 Platform

Note on Support

Whilst this is technically possible now an official server-side compiler hasn't been released. Official support for server-side compilation could be added in future releases.

Last updated