Diff
checker
Texto
Texto
Imágenes
Documentos
Excel
Carpetas
Legal
Enterprise
Aplicación de escritorio
Precios
Iniciar sesión
Descargar Diffchecker Desktop
Comparar texto
Encuentra la diferencia entre dos archivos de texto
Herramientas
Historial
Editor live
Ocultar espacios en blanco
Ocultar sin cambios
Sin ajuste de línea
Vista
Dividido
Unificado
Nivel de detalle
Inteligente
Palabra
Letra
Estilos de texto
Cambiar apariencia
Resaltado de sintaxis
Elegir sintaxis
Ignorar
Transformar texto
Ir al primer cambio
Editar entrada
Diffchecker Desktop
La forma más segura de usar Diffchecker. ¡Obtén la app de Diffchecker Desktop: tus diffs nunca salen de tu computadora!
Obtener Desktop
Shared Theme Context - 2
Creado
hace 3 meses
El diff nunca expira
Borrar
Exportar
Compartir
Explicar
4 eliminaciones
Líneas
Total
Eliminado
Caracteres
Total
Eliminado
Para continuar usando esta función, actualice a
Diff
checker
Pro
Ver precios
22 líneas
Copiar todo
42 adiciones
Líneas
Total
Añadido
Caracteres
Total
Añadido
Para continuar usando esta función, actualice a
Diff
checker
Pro
Ver precios
57 líneas
Copiar todo
Copiar
Copiado
Copiar
Copiado
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";
Copiar
Copiado
Copiar
Copiado
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";
});
});
Copiar
Copiado
Copiar
Copiado
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]);
Copiar
Copiado
Copiar
Copiado
const toggle = () => setTheme((t) => (t === "light" ? "dark" : "light"));
const toggle = () => setTheme((t) => (t === "light" ? "dark" : "light"));
Copiar
Copiado
Copiar
Copiado
const value = useMemo(() => ({ theme, setTheme, toggle }), [theme]);
Copiar
Copiado
Copiar
Copiado
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;
}
}
Diferencias guardadas
Texto original
Abrir archivo
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 }; }
Texto modificado
Abrir archivo
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; }
Encontrar la diferencia