Socket
Socket
Sign inDemoInstall

tss-react

Package Overview
Dependencies
Maintainers
1
Versions
188
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


Version published
Weekly downloads
223K
increased by5.58%
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

FAQs

Package last updated on 18 Oct 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc