useTrackedEffect
A hook of useEffect that allow us to track which dependencies caused the effect to trigger.
Overview
A hook of useEffect that allow us to track which dependencies caused the effect to trigger.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTrackedEffect.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTrackedEffect.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTrackedEffect.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTrackedEffect.jsonA hook of useEffect that allow us to track which dependencies caused the effect to trigger.
Examples
Basic usage
API
useTrackedEffect(
effect: (changes: [], previousDeps: [], currentDeps: []) => (void | (() => void | undefined)),
deps?: deps,
)The API is alike React.useEffect, but the first function will receive three parameters: changes, previousDeps, and currentDeps.
- changes: Index of changed dependencies
- previousDeps: Last deps
- currentDeps: Current deps