The rule that helped me most: every value that is used inside an effect and can change over time must be in the dependency array. If adding it causes a loop, the loop is revealing a design problem.
In your case: data is updated inside the effect, and you're also depending on data — that's the loop. Separate the concerns into two effects as shown above.