From the docs:
https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#save
Note: The save function should be a pure function that depends only on the attributes used to invoke it.
It can not have any side effect or retrieve information from another source, e.g. it is not possible to use the data module inside itselect( store ).selector( ... )
.
This is because if the external information changes, the block may be flagged as invalid when the post is later edited (read more about Validation).
If there is a need to have other information as part of the save, developers can consider one of these two alternatives:
- Use dynamic blocks and dynamically retrieve the required information on the server.
- Store the external value as an attribute which is dynamically updated in the block’s edit function as changes occur.