React API

Use the React hooks and provider for seamless integration with React applications.

Import

import { useResetTheme, ThemeProvider, useTheme } from 'ospinajuanp-reset-css/react';

ThemeProvider

NameTypeDefaultDescription
defaultThemeThemeNameundefinedThe default theme to apply on initial render. If not provided, no theme is applied.
childrenReactNode-The child components that will have access to the theme context.

useResetTheme Hook

NameTypeDefaultDescription
initialThemeThemeNameundefinedThe initial theme for this hook instance.

Return Value

NameTypeDefaultDescription
themeThemeName-The current active theme.
setTheme(theme: ThemeName) => void-Function to change the current theme.
themesThemeName[]-Array of all available theme names.

useTheme Hook

Use useTheme inside a ThemeProvider to access the theme context. Returns the same object as useResetTheme.

Usage Examples

Using useResetTheme directly

import { useResetTheme } from 'ospinajuanp-reset-css/react';

function ThemeSwitcher() {
  const { theme, setTheme, themes } = useResetTheme('dark');

  return (
    <div>
      <p>Current theme: {theme}</p>
      <select value={theme} onChange={(e) => setTheme(e.target.value)}>
        {themes.map(t => <option key={t} value={t}>{t}</option>)}
      </select>
    </div>
  );
}

Using ThemeProvider

import { ThemeProvider, useTheme } from 'ospinajuanp-reset-css/react';

function ThemeSwitcher() {
  const { theme, setTheme, themes } = useTheme();
  return (
    <select value={theme} onChange={(e) => setTheme(e.target.value)}>
      {themes.map(t => <option key={t} value={t}>{t}</option>)}
    </select>
  );
}

export default function App() {
  return (
    <ThemeProvider defaultTheme="dark">
      <ThemeSwitcher />
    </ThemeProvider>
  );
}