New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tss-react

Package Overview
Dependencies
Maintainers
1
Versions
191
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tss-react

Type safe CSS-in-JS API heavily inspired by react-jss

4.9.16
latest
Source
npm
Version published
Weekly downloads
271K
0.82%
Maintainers
1
Weekly downloads
 
Created

What is tss-react?

tss-react is a TypeScript-first CSS-in-JS library for React that allows you to write type-safe styles using TypeScript. It provides a simple and efficient way to manage styles in your React applications, leveraging the power of TypeScript for better type safety and developer experience.

What are tss-react's main functionalities?

Type-safe CSS-in-JS

This feature allows you to create type-safe styles using TypeScript. The `makeStyles` function generates a hook that you can use to apply styles to your components.

```typescript
import { makeStyles } from 'tss-react/makeStyles';

const useStyles = makeStyles()((theme) => ({
  root: {
    backgroundColor: theme.palette.primary.main,
    padding: theme.spacing(2),
  },
}));

function MyComponent() {
  const { classes } = useStyles();
  return <div className={classes.root}>Hello, World!</div>;
}
```

Theming support

tss-react supports theming, allowing you to create and use themes in your application. This example demonstrates how to create a theme and apply it to a component using the `ThemeProvider` from Material-UI.

```typescript
import { ThemeProvider, createTheme } from '@mui/material/styles';
import { makeStyles } from 'tss-react/makeStyles';

const theme = createTheme({
  palette: {
    primary: {
      main: '#1976d2',
    },
  },
});

const useStyles = makeStyles()((theme) => ({
  root: {
    backgroundColor: theme.palette.primary.main,
    padding: theme.spacing(2),
  },
}));

function MyComponent() {
  const { classes } = useStyles();
  return <div className={classes.root}>Hello, World!</div>;
}

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

Dynamic styles

This feature allows you to create dynamic styles based on props. The `makeStyles` function can accept a parameter that you can use to generate styles dynamically.

```typescript
import { makeStyles } from 'tss-react/makeStyles';

const useStyles = makeStyles<{ color: string }>()((theme, { color }) => ({
  root: {
    backgroundColor: color,
    padding: theme.spacing(2),
  },
}));

function MyComponent({ color }: { color: string }) {
  const { classes } = useStyles({ color });
  return <div className={classes.root}>Hello, World!</div>;
}
```

Other packages similar to tss-react

Keywords

jss

FAQs

Package last updated on 28 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts