Diff
checker
Texto
Texto
Imagens
Documentos
Excel
Pastas
Legal
Enterprise
Aplicativo para desktop
Preços
Fazer login
Baixar o Diffchecker Desktop
Comparar texto
Encontre a diferença entre dois arquivos de texto
Ferramentas
Histórico
Editor live
Ocultar espaços em branco
Recolher inalteradas
Sem quebra de linha
Layout
Dividido
Unificado
Nível de detalhe
Inteligente
Palavra
Caractere
Estilos de texto
Alterar aparência
Realce de sintaxe
Escolher sintaxe
Ignorar
Transformar texto
Ir à primeira mudança
Editar entrada
Diffchecker Desktop
A maneira mais segura de usar o Diffchecker. Obtenha o aplicativo Diffchecker Desktop: seus diffs nunca saem do seu computador!
Obter Desktop
Shared Theme Context - 2
Criado
há 3 meses
O diff nunca expira
Limpar
Exportar
Compartilhar
Explicar
4 remoções
Linhas
Total
Removido
Caracteres
Total
Removido
Para continuar usando este recurso, atualize para
Diff
checker
Pro
Ver preços
22 linhas
Copiar tudo
42 adições
Linhas
Total
Adicionado
Caracteres
Total
Adicionado
Para continuar usando este recurso, atualize para
Diff
checker
Pro
Ver preços
57 linhas
Copiar tudo
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;
}
}
Diferenças salvas
Texto original
Abrir arquivo
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 alterado
Abrir arquivo
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 Diferença