Creating my own “recent blog posts” static Gutenberg block, can’t use react hooks in the frontend

That’s not how blocks work, the save component generates static HTML, so you can’t use interactive hooks or state.

The important part is that the save component only runs inside the editor on your browser. It does not run in the database, or on the client. You can’t save a react component to the database and render it with interactivity on the frontend.

Instead if you want to fetch the 3 latest posts you have 2 options:

  • enqueue a JS file on the frontend that fetches the posts from the REST API
  • save null and use PHP filters to render the 3 latest posts

The latter is how core does it for full site editing blocks