01 · Before and afterThe pattern
// before: fires on the loading render too
useEffect(() => { if (id && !item) close() }, [id, item])
// after: only when the request has actually finished
const { data: item, isSuccess, isError } = useItemQuery(id)
useEffect(() => {
if (id && ((isSuccess && !item) || isError)) close()
}, [id, item, isSuccess, isError])02 · Run it on your appThe check
Does any screen redirect, toast “not found” or close a panel based on missing data without checking that the request has finished?
If the honest answer is no or not sure, this is worth a look before it reaches production.