Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@callstack/react-theme-provider

Package Overview
Dependencies
Maintainers
9
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@callstack/react-theme-provider

Theme provider for react and react-naitve applications

  • 1.0.6
  • Source
  • npm
  • Socket score

Version published
Maintainers
9
Created

What is @callstack/react-theme-provider?

@callstack/react-theme-provider is a library that allows you to easily manage and apply themes in your React applications. It provides a context-based solution for theming, enabling you to define and switch between different themes dynamically.

What are @callstack/react-theme-provider's main functionalities?

ThemeProvider

The ThemeProvider component is used to wrap your application or a part of it, providing the theme to all the components within its tree. This allows you to define a theme object and make it available throughout your application.

import { ThemeProvider } from '@callstack/react-theme-provider';

const theme = {
  colors: {
    primary: '#6200ee',
    background: '#ffffff',
    surface: '#ffffff',
    accent: '#03dac4',
    error: '#b00020',
    text: '#000000',
    onPrimary: '#ffffff',
    onBackground: '#000000',
    onSurface: '#000000',
    onAccent: '#000000',
    onError: '#ffffff',
  },
};

const App = () => (
  <ThemeProvider theme={theme}>
    <YourComponent />
  </ThemeProvider>
);

useTheme Hook

The useTheme hook allows you to access the current theme within your functional components. This hook returns the theme object, which you can then use to style your components dynamically based on the current theme.

import { useTheme } from '@callstack/react-theme-provider';

const ThemedComponent = () => {
  const theme = useTheme();

  return (
    <div style={{ backgroundColor: theme.colors.background, color: theme.colors.text }}>
      This component is themed!
    </div>
  );
};

withTheme Higher-Order Component

The withTheme higher-order component (HOC) is used to inject the theme into your class components. This HOC wraps your component and passes the theme as a prop, allowing you to access and use the theme within your class components.

import { withTheme } from '@callstack/react-theme-provider';

const ThemedComponent = ({ theme }) => (
  <div style={{ backgroundColor: theme.colors.background, color: theme.colors.text }}>
    This component is themed!
  </div>
);

export default withTheme(ThemedComponent);

Other packages similar to @callstack/react-theme-provider

Keywords

FAQs

Package last updated on 08 Oct 2018

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