This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * OpenTelemetry Instrumentation for Next.js | |
| * | |
| * This file sets up distributed tracing and metrics collection. | |
| * | |
| * Architecture: | |
| * - Traces: Handled by OTEL with MINIMAL modifications (only add http.route) | |
| * - Metrics: Recorded in responseHook with complete request/response data | |
| * - Routes: Normalized to reduce cardinality (e.g., /order/123 → /order/:id) | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import "./App.css"; | |
| import { useTheme } from "./hooks/useTheme"; | |
| import useThemeStore from "./stores/useThemeStore"; | |
| function App() { | |
| const toggleTheme = useThemeStore((state) => state.toggleTheme); | |
| useTheme(); | |
| return ( | |
| <div className="h-screen bg-white dark:bg-black flex items-center justify-center"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect } from "react"; | |
| import useThemeStore from "../stores/useThemeStore"; | |
| import { applyThemePreference } from "../utils/themeUtils"; | |
| const selector = (state) => state.theme; | |
| export const useTheme = () => { | |
| const theme = useThemeStore(selector); | |
| useEffect(() => { | |
| applyThemePreference(theme); | |
| }, [theme]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect } from "react"; | |
| import "./App.css"; | |
| import useThemeStore from "./stores/useThemeStore"; | |
| import { applyThemePreference } from "./utils/themeUtils"; | |
| function App() { | |
| const toggleTheme = useThemeStore((state) => state.toggleTheme); | |
| const theme = useThemeStore((state) => state.theme); | |
| useEffect(() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = { | |
| purge: ["./src/**/*.{js,jsx,ts,tsx}", "./public/index.html"], | |
| darkMode: "class", // or 'media' or 'class' | |
| theme: {}, | |
| variants: { | |
| extend: {}, | |
| }, | |
| plugins: [], | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import create from "zustand"; | |
| import { persist } from "zustand/middleware"; | |
| import { THEME_TYPES } from "../constants"; | |
| const { THEME_LIGHT, THEME_DARK } = THEME_TYPES; | |
| const useThemeStore = create( | |
| persist( | |
| (set) => ({ | |
| theme: THEME_LIGHT, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { THEME_TYPES } from "../constants"; | |
| // for tailwind css, need the change the root | |
| export const applyThemePreference = (theme) => { | |
| const { THEME_DARK, THEME_LIGHT } = THEME_TYPES; | |
| const root = window.document.documentElement; | |
| const isDark = theme === THEME_DARK; | |
| root.classList.remove(isDark ? THEME_LIGHT : THEME_DARK); | |
| root.classList.add(theme); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const THEME_TYPES = { | |
| THEME_DARK: "dark", | |
| THEME_LIGHT: "light", | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import "./App.css"; | |
| function App() { | |
| return ( | |
| <div className="h-screen bg-white dark:bg-black flex items-center justify-center"> | |
| <div className="shadow-xl flex flex-col space-y-6 items-center justify-center p-16 dark:bg-gray-900"> | |
| <span className="dark:text-white text-black font-bold text-xl"> | |
| Let's build dark mode with react. | |
| </span> | |
| <button |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let React = (function() { | |
| let global = {}; // define a global variable where we store information about the component | |
| let index = 0; // index to keep track of the component's state | |
| function render(Component) { | |
| global.Component = Component; | |
| const instance = Component(); // get the instance of the component | |
| index = 0; | |
| instance.render(); // call the component's render function | |
| global.instance = instance; // store the component's instance for any future calls of the component's functions |
NewerOlder