Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

547 B
Raw Blame
/* Copyright 2026 Marimo. All rights reserved. */

import { dequal } from "dequal";
import React from "react";

/**
 * Deep compare memoize hook
 *
 * Useful when you want to memoize a react hook that has an object as a dependency
 * that you want to compare by value instead of reference.
 *
 * Useful when the re-render if more expensive than the deep compare.
 */
export function useDeepCompareMemoize<T>(value: T) {
  const ref = React.useRef(value);

  if (!dequal(value, ref.current)) {
    ref.current = value;
  }

  return ref.current;
}