Diff
checker
Texte
Texte
Images
Documents
Excel
Dossiers
Legal
Enterprise
Application de bureau
Prix
Se connecter
Télécharger Diffchecker Desktop
Comparer le texte
Trouver la différence entre deux fichiers texte
Outils
Historique
Éditeur live
Masquer les espaces
Cacher identiques
Sans retour à la ligne
Vue
Divisé
Unifié
Niveau de précision
Intelligent
Mot
Caractère
Styles de texte
Modifier l’apparence
Coloration syntaxique
Choisir la syntaxe
Ignorer
Transformer le texte
Aller au premier écart
Modifier l'entrée
Diffchecker Desktop
La façon la plus sécurisée d'utiliser Diffchecker. Obtenez l'application Diffchecker Desktop : vos diffs ne quittent jamais votre ordinateur !
Obtenir Desktop
Shared Theme Context - 2
Créé
il y a 3 mois
Le diff n'expire jamais
Effacer
Exporter
Partager
Expliquer
4 suppressions
Lignes
Total
Supprimé
Caractères
Total
Supprimé
Pour continuer à utiliser cette fonctionnalité, passez à
Diff
checker
Pro
Voir les prix
22 lignes
Copier tout
42 ajouts
Lignes
Total
Ajouté
Caractères
Total
Ajouté
Pour continuer à utiliser cette fonctionnalité, passez à
Diff
checker
Pro
Voir les prix
57 lignes
Copier tout
Copier
Copié
Copier
Copié
import {
useEffect,
useState
} from "react";
import {
createElement,
createContext,
type Dispatch,
type PropsWithChildren,
type SetStateAction,
useContext,
useEffect,
useMemo,
useState
,
} from "react";
type Theme = "light" | "dark";
type Theme = "light" | "dark";
Copier
Copié
Copier
Copié
export function
useTheme(
) {
interface ThemeContextValue {
theme: Theme;
setTheme: Dispatch<SetStateAction<Theme>>;
toggle: () => void;
}
const ThemeContext = createContext<ThemeContextValue | null>(null);
export function
ThemeProvider({ children }: PropsWithChildren
) {
const [theme, setTheme] = useState<Theme>(() => {
const [theme, setTheme] = useState<Theme>(() => {
if (typeof window !== "undefined") {
if (typeof window !== "undefined") {
return (localStorage.getItem("theme") as Theme) || "light";
return (localStorage.getItem("theme") as Theme) || "light";
}
}
return "light";
return "light";
});
});
Copier
Copié
Copier
Copié
useEffect(() => {
useEffect(() => {
const root = document.documentElement;
const root = document.documentElement;
root.classList.toggle("dark", theme === "dark");
root.classList.toggle("dark", theme === "dark");
localStorage.setItem("theme", theme);
localStorage.setItem("theme", theme);
}, [theme]);
}, [theme]);
Copier
Copié
Copier
Copié
const toggle = () => setTheme((t) => (t === "light" ? "dark" : "light"));
const toggle = () => setTheme((t) => (t === "light" ? "dark" : "light"));
Copier
Copié
Copier
Copié
const value = useMemo(() => ({ theme, setTheme, toggle }), [theme]);
Copier
Copié
Copier
Copié
return
{ theme, setTheme, toggle };
return
createElement(ThemeContext.Provider, { value }, children);
}
export function useTheme() {
const context = useContext(ThemeContext);
if (!context) {
throw new Error("useTheme must be used within a ThemeProvider");
}
return context;
}
}
Différences enregistrées
Texte d'origine
Ouvrir un fichier
import { useEffect, useState } from "react"; type Theme = "light" | "dark"; export function useTheme() { const [theme, setTheme] = useState<Theme>(() => { if (typeof window !== "undefined") { return (localStorage.getItem("theme") as Theme) || "light"; } return "light"; }); useEffect(() => { const root = document.documentElement; root.classList.toggle("dark", theme === "dark"); localStorage.setItem("theme", theme); }, [theme]); const toggle = () => setTheme((t) => (t === "light" ? "dark" : "light")); return { theme, setTheme, toggle }; }
Texte modifié
Ouvrir un fichier
import { createElement, createContext, type Dispatch, type PropsWithChildren, type SetStateAction, useContext, useEffect, useMemo, useState, } from "react"; type Theme = "light" | "dark"; interface ThemeContextValue { theme: Theme; setTheme: Dispatch<SetStateAction<Theme>>; toggle: () => void; } const ThemeContext = createContext<ThemeContextValue | null>(null); export function ThemeProvider({ children }: PropsWithChildren) { const [theme, setTheme] = useState<Theme>(() => { if (typeof window !== "undefined") { return (localStorage.getItem("theme") as Theme) || "light"; } return "light"; }); useEffect(() => { const root = document.documentElement; root.classList.toggle("dark", theme === "dark"); localStorage.setItem("theme", theme); }, [theme]); const toggle = () => setTheme((t) => (t === "light" ? "dark" : "light")); const value = useMemo(() => ({ theme, setTheme, toggle }), [theme]); return createElement(ThemeContext.Provider, { value }, children); } export function useTheme() { const context = useContext(ThemeContext); if (!context) { throw new Error("useTheme must be used within a ThemeProvider"); } return context; }
Trouver la différence