Loading...
Please waitLoading...
Please waitRun effects only when the component updates, not on the initial render, with the useUpdateEffect hook, providing a way to execute code after updates without affecting the initial render.
pnpm dlx shadcn@latest add https://usekit.kiron.dev/k/use-update-effect
"use client"
import { useUpdateEffect } from "@/hooks/use-update-effect"
export function Component() {
const [count, setCount] = React.useState(0)
useUpdateEffect(() => {
console.log("Component updated, count:", count)
}, [count])
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
</div>
)
}
Name | Type | Description | Default Value | Optional |
---|---|---|---|---|
callback | () => void | Function to run on component updates. | - | No |
deps | React.DependencyList | Dependencies for the effect, similar to useEffect . | [] | Yes |