Skip to content

Instantly share code, notes, and snippets.

View bkeys818's full-sized avatar
⛰️
Climbing rocks

Ben Keys bkeys818

⛰️
Climbing rocks
View GitHub Profile
@bkeys818
bkeys818 / logReactStateUpdates.ts
Created January 13, 2024 17:41
A method that will write a will log any updates to a React state value. This is epecially usefull for tracking changes of the actual value, not the memory location.
import { useRef } from "react";
import { appendFileSync } from "fs";
import { resolve } from "path";
const logFilePath = resolve(__dirname, "./stateUpdates.log");
export function logUpdates(name: string, value: any) {
const ref = useRef();
value = mapObjects(value, simplifyObject);
if (!isEqualValue(ref.current, value)) {