Skip to main content
Glama
useTheme.ts744 B
import { useState, useEffect } from 'react'; type Theme = 'light' | 'dark'; export function useTheme() { const [theme, setTheme] = useState<Theme>(() => { const savedTheme = localStorage.getItem('theme') as Theme; if (savedTheme) { return savedTheme; } return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; }); useEffect(() => { document.documentElement.classList.remove('light', 'dark'); document.documentElement.classList.add(theme); localStorage.setItem('theme', theme); }, [theme]); const toggleTheme = () => { setTheme(prevTheme => prevTheme === 'light' ? 'dark' : 'light'); }; return { theme, toggleTheme, isDark: theme === 'dark' }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/xwang152-jack/wechat-official-account-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server