Docs
useDomReady

Detect when the DOM is fully loaded and ready for manipulation with the useDomReady hook, providing a way to execute code after the DOM is ready.

Installation

pnpm dlx shadcn@latest add https://usekit.kiron.dev/k/use-dom-ready

Usage

"use client"
 
import { useDomReady } from "@/hooks/use-dom-ready"
 
export function Component() {
  useDomReady(() => {
    console.log("DOM is interactive or complete!")
    // Example: Initialize a DOM-dependent library
    const element = document.getElementById("my-element")
    if (element) {
      element.style.backgroundColor = "blue"
    }
  })
 
  return (
    <div style={{ padding: "20px", maxWidth: "600px", margin: "0 auto" }}>
      <p>This component will log a message when the DOM is ready.</p>
      <div
        id="my-element"
        style={{ height: "100px", backgroundColor: "lightgray" }}
      >
        My Element
      </div>
    </div>
  )
}

API Reference

Parameters

NameTypeDescriptionDefault ValueOptional
callback() => voidFunction to execute when the DOM is ready.-No

Return Values

NameTypeDescription
isDomReadybooleanIndicates whether the DOM is ready for manipulation.