React-JSS

10.10.0 · abandoned · verified Sun Apr 19

JSS is a CSS-in-JS library that allows developers to author styles using JavaScript. `react-jss` provides a robust integration layer for using JSS within React applications, leveraging hooks (like `createUseStyles`) and a `ThemeProvider` for contextual styling. It enables dynamic styling, global styles, and efficient style injection into the DOM. The current stable version is 10.10.0, though the project is explicitly stated as no longer maintained as of v10.10.1. This means new features, critical bug fixes, or compatibility updates for newer React versions (beyond what was already addressed) are not expected. Historically, it offered a performant and feature-rich alternative to other CSS-in-JS solutions, supporting various plugins for advanced styling patterns like nesting and global rules. Due to its abandonment, it is generally not recommended for new projects and existing projects should consider migration. Its release cadence was irregular towards its end, with several alpha and patch releases addressing React 18 compatibility and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to set up `react-jss` with a `ThemeProvider` to provide global theme values and use `createUseStyles` for component-scoped styling, including dynamic values based on the theme.

import React from 'react';
import { createUseStyles, ThemeProvider } from 'react-jss';

interface Theme {
  primary: string;
  secondary: string;
  fontSize: number;
}

const theme: Theme = {
  primary: '#007bff',
  secondary: '#6c757d',
  fontSize: 16,
};

const useStyles = createUseStyles<keyof Theme> ({
  button: {
    backgroundColor: ({ primary }) => primary,
    color: 'white',
    padding: '10px 20px',
    border: 'none',
    borderRadius: '5px',
    fontSize: ({ fontSize }) => `${fontSize}px`,
    cursor: 'pointer',
    '&:hover': {
      opacity: 0.9,
    },
  },
  secondaryButton: {
    backgroundColor: ({ secondary }) => secondary,
    color: 'white',
    padding: '10px 20px',
    border: 'none',
    borderRadius: '5px',
    fontSize: ({ fontSize }) => `${fontSize}px`,
    cursor: 'pointer',
    marginLeft: '10px',
    '&:hover': {
      opacity: 0.9,
    },
  },
});

function MyButton() {
  const classes = useStyles(theme); // styles can receive props or use the theme from context
  return (
    <div>
      <button className={classes.button}>Primary Button</button>
      <button className={classes.secondaryButton}>Secondary Button</button>
    </div>
  );
}

function App() {
  return (
    <ThemeProvider theme={theme}>
      <MyButton />
    </ThemeProvider>
  );
}

export default App;

view raw JSON →