If you have multiple dynamic blocks with a post loop on a page, how do you avoid duplicates from inside the render_callback function?

In PHP I recall these ways

  1. Static variables
  2. Class properties
  3. Databases, Files, Memory (might be flushed though)

to preserve a state, in a hook’s callback, that is called multiple times in WordPress and in the order I would consider using myself but it depends on the context (eg WP transients, that store data that expires, can use memory for speedy recalling and database as a fallback).

Global variables might also be listed at the bottom (usually not recommended) and closure tricks closer to the top.