Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/soyleninjs/hequalizer/llms.txt

Use this file to discover all available pages before exploring further.

Hequalizer is framework-agnostic — it has no dependencies and interacts only with the DOM and window. Any framework that renders HTML elements can use it. The only requirement is that the target elements exist in the DOM before you create an instance, and that you call destroy() when those elements are removed to prevent memory leaks and stale resize listeners.
React’s virtual DOM means elements are not available until after the component mounts. Create the Hequalizer instance inside a useEffect hook so it always runs after the initial render, and return destroy() as the cleanup function so React tears down the instance when the component unmounts.
1

Load Hequalizer before your React app

Hequalizer ships as a plain script that sets window.Hequalizer. Add it to your HTML before your bundle, or import the file directly in your entry point:
index.html
<script src="https://cdn.jsdelivr.net/npm/hequalizer/hequalizer.min.js"></script>
2

Create and destroy the instance in useEffect

ProductGrid.jsx
import { useEffect, useRef } from 'react';

function ProductGrid() {
  const hequalizerRef = useRef(null);

  useEffect(() => {
    hequalizerRef.current = new window.Hequalizer('product-title', {
      columns: 3,
      responsive: {
        768: { columns: 1 }
      }
    });

    return () => {
      hequalizerRef.current?.destroy();
    };
  }, []);

  return (
    <div className="grid">
      <h3 data-hequalizer="product-title">Product 1</h3>
      <h3 data-hequalizer="product-title">Longer Product Name</h3>
      <h3 data-hequalizer="product-title">Product 3</h3>
    </div>
  );
}

export default ProductGrid;
The empty dependency array [] ensures the effect runs once on mount. The cleanup function returned from useEffect calls destroy(), which removes the resize listener, disconnects MutationObserver instances, and removes the instance from Hequalizer’s internal registry — freeing the handle for reuse.
3

Refresh elements when the item list changes

If your component renders a dynamic list of items, call refreshElements() inside a second effect that depends on your items array:
ProductGrid.jsx
import { useEffect, useRef } from 'react';

function ProductGrid({ products }) {
  const hequalizerRef = useRef(null);

  useEffect(() => {
    hequalizerRef.current = new window.Hequalizer('product-title', {
      columns: 3
    });

    return () => {
      hequalizerRef.current?.destroy();
    };
  }, []);

  useEffect(() => {
    hequalizerRef.current?.refreshElements();
  }, [products]);

  return (
    <div className="grid">
      {products.map((product) => (
        <h3 key={product.id} data-hequalizer="product-title">
          {product.title}
        </h3>
      ))}
    </div>
  );
}
refreshElements() re-queries the DOM for [data-hequalizer="product-title"], picks up any newly rendered elements, and recalculates heights.
Keep the Hequalizer instance in a useRef rather than useState. Storing it in state would trigger a re-render when the instance is assigned, which is unnecessary — the instance is a side-effect object, not UI state.
When using Hequalizer with a SPA router (React Router, Vue Router, etc.), call destroy() when navigating away from any view that contains equalized elements, then create a new instance when that view mounts again. Failing to destroy leaves an orphaned resize listener and a registered handle that will cause the constructor to throw a “handle already in use” error the next time the view mounts.
Use window.Hequalizer.getInstance(handle) in component lifecycle hooks to access an existing instance without threading a reference through props or a context. Because Hequalizer maintains a static internal Map keyed by handle, getInstance always returns the live instance from anywhere in your application.

Build docs developers (and LLMs) love