Step 2: Enhancing the Monitor with Detailed Insights
Once you have a basic monitor set up, the next step is to enhance your monitoring by adding more detailed insights about Cumulative Layout Shift (CLS). This will help you understand not just the overall CLS score but also specific details like individual layout shifts, their causes, and contributing elements. Here's how you can extend your PerformanceMonitor component:
Adding Detailed Insights
- Capture Individual Layout Shifts: Instead of only capturing the final CLS value, capture each individual layout shift event as it happens.
- Identify Contributing Elements: Determine which specific DOM elements are causing layout shifts and log their details.
Here's an enhanced version of your PerformanceMonitor component:
tsx1// components/PerformanceMonitor.tsx 2"use client"; 3 4import { useEffect } from "react"; 5import { useCLS } from "@page-speed/hooks"; 6 7export function PerformanceMonitor() { 8 const [state, dispatch] = useCLS({ 9 onMeasure: (value, rating) => { 10 console.log(`Final CLS: ${value.toFixed(3)} (${rating})`); 11 12 // Send final CLS value to analytics 13 if (typeof window !== " 14 15[Read the full article at DEV Community](https://dev.to/opensite/stop-your-react-app-from-shifting-a-deep-dive-into-usecls-from-page-speedhooks-1e9f) 16 17--- 18 19**Want to create content about this topic?** [Use Nemati AI tools](https://nemati.ai) to generate articles, social posts, and more.

![[AINews] The Unreasonable Effectiveness of Closing the Loop](/_next/image?url=https%3A%2F%2Fmedia.nemati.ai%2Fmedia%2Fblog%2Fimages%2Farticles%2F600e22851bc7453b.webp&w=3840&q=75)



