Skip to content

Instantly share code, notes, and snippets.

@arkatsy
arkatsy / zustand-internals.jsx
Last active June 11, 2024 21:35
How zustand works internally
import { useSyncExternalStore } from "react";
// For more on the useSyncExternalStore hook, see https://react.dev/reference/react/useSyncExternalStore
// The code is almost identical to the source code of zustand, without types and some features stripped out.
// Check the links to see the references in the source code.
// The links are referencing the v5 of the library. If you plan on reading the source code yourself v5 is the best way to start.
// The current v4 version contains lot of deprecated code and extra stuff that makes it hard to reason about if you're new to this.
// https://github.com/pmndrs/zustand/blob/fe47d3e6c6671dbfb9856fda52cb5a3a855d97a6/src/vanilla.ts#L57-L94
function createStore(createState) {
// Name: Toggle System Theme
// Author: arkatsy
// Description: Toggles the system theme between light and dark mode.
import "@johnlindquist/kit";
import * as _regedit from "regedit";
import { exec } from "child_process";
const regedit = _regedit.promisified;
const REGISTRY_PATH = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";