Skip to content

Conversation

salaarkhan-dev
Copy link

Add useTheme Hook for Theme Management

Description

This PR introduces a new useTheme custom hook that provides a clean and type-safe way to manage themes in AdminJS applications. The hook is built with TypeScript and includes performance optimizations.

Changes

  • Added useTheme hook with TypeScript support
  • Implemented memoization for better performance
  • Added comprehensive documentation
  • Included TypeScript type definitions
  • Added error handling and development warnings

Features

  • Get current theme information
  • Switch between available themes
  • Check if a specific theme is active
  • Access all available themes
  • Full TypeScript support with proper type inference

Usage

import { useTheme } from 'adminjs'

function ThemeSwitcher() {
  const { theme, setTheme, availableThemes, isThemeActive } = useTheme()
  
  return (
    <select 
      value={theme?.id} 
      onChange={(e) => setTheme(e.target.value)}
    >
      {availableThemes.map(t => (
        <option key={t.id} value={t.id}>
          {t.name} {isThemeActive(t.id) && '(Active)'}
        </option>
      ))}
    </select>
  )
}

@salaarkhan-dev salaarkhan-dev closed this by deleting the head repository Aug 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant