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
nulland use PHP filters to render the 3 latest posts
The latter is how core does it for full site editing blocks
Related Posts:
- Unable to trigger a frontend @wordpress/hooks action
- Hide gutenberg option blocks
- Disable block from editor based on post type
- WordPress v5.0.3 Gutenberg & JS error “Uncaught SyntaxError: missing ) after argument list”
- Gutenberg gallery hook errors
- What is the best filter where to use register_block_type?
- @wordpress/hooks use to add actions/filters within multiple plugin
- How to extend custom (non-core) blocks?
- Is it possible to switch Gutenberg’s editor styles when document settings change?
- How do I run an action after a featured image has been selected in the Gutenberg editor?
- WordPress How to reorder Page/Post Settings
- How To Apply Different Styles To All Blocks Based on Post Meta Value?
- getSaveContent.extraProps hook for core/post-title doesn’t add new attributes on to the frontend
- How to set Post ID from context to an attribute in child block of Gutenberg Query Loop
- The enqueue_block_assets is changing the styles of the editor interface
- Replacing specific Gutenberg blocks
- useSelect() plus resolver result is serving cached data incorrectly
- How to know what functions are hooked to an action/filter?
- How do I implement the WordPress Iris picker into my plugin on the front-end?
- What is “all” in isset($wp_filter[‘all’])
- Please explain how these hooks work
- Hook ‘wp_enqueue_scripts’ priority has no effect
- Hook *after* user password change?
- Does anyone have a visual breakdown of core hooks and when they are fired?
- The ‘user_has_cap’ hook seems to take two page loads to trigger
- How and where can we request new WordPress hooks to be added?
- WordPress Admin Tooltip hooks
- Wp_update_post: Infinite loop even with remove_action solution, OOP
- RSS Feed Custom Title?
- Detect type of post status transition
- hook for lostpassword form
- What do the args for Gutenberg subpackage “hooks” function “doAction” mean?
- How and why can a hook call itself without causing recursion?
- Is This A Correct Example Usage Of current_filter()?
- Seeking Hook Whenever a Custom Taxonomy Term Has Been Added
- How can i trigger an action manually?
- Can I trigger the publish_post hook by using wp_insert_post?
- WooCommerce New customer email Hook? [closed]
- admin_notices not working in post editor
- How to detect when a user changes their name?
- How to check what kind of saving it is?
- Override wp_delete_post and move to trash instead for custom post type
- How do I grab specific posts (by post id) and display the title, featured image, and excerpt?
- Empty Super Cache programmatically (with ACF action) [closed]
- Hook all http requests
- Setting Cookie with init hook causes ‘header already sent’
- Is there an “Add Page” hook?
- How To Make Sure That My Action Hook Executes Last
- Does update_comment_meta hook exists?
- how to determine how many and what kind of arguments are passed to hooks
- Can not set custom title on some WordPress setups
- BuddyPress User Profile Menu
- How to hook in after user’s registration email has been sent?
- Checking post format during xmlrpc_publish_post
- Hook for when a page template is changed
- Append a code when at the current page in wp_list_pages()
- Footer.php being inserted before article closing tag?
- Get all posts with a duplicate name
- Save acf field data via acf/save_post before post is saved
- Above-the-fold inline styles from SASS generated stylesheet
- Redirect in form handler causing form to be submitted twice
- Checking login status before wp_get_current_user is initialised
- Add media library tab
- Conditional hook [closed]
- Add_menu_page() error message -> “You do not have sufficient permissions to access this page”
- Where is the right place to register/enqueue scripts & styles
- Displaying list of cities according to the selected state. Using the WordPress hook
- Removing parent theme action on pluggable function not working
- Removing a Filter
- Which action hook should I use to intercept a form upon submission?
- Where Are Hooks?
- WordPress wp_loaded action hook
- useSelect second parameter
- Check if `do_action()` in WordPress returns any result
- add_action hook for publish_post not working
- Modify Notification Message When Profile Updated
- Hook for inserting?
- How to stop WordPress from updating the post meta
- Can an RSS item be altered with a hook?
- Block Update Profile Errors
- How to remove a meta description or other contents
- Delay action unltil the untill previous (hoocked) action is completed
- Trigger function on Remove block or add new block in Gutenberg JavaScript
- What is the hook to remove a menu items group from Appearance > Menus column Add menu items
- Add stuff above header edit form
- Add HTML code before the title of the Tag page
- Hooks with same priority number. Can one stack items returned in divs, position: absolute each with their own z-index?
- trying to locate the correct file to edit my internal linking anchor tags
- Send email to post author 1 day before his project ends
- can’t access dashboard and showing forbidden page
- prepopulate form from a hook within wordpress function.php file
- Change Title Type
- admin_post hook not working
- What is meaning of BEFORE and AFTER in this hook name?
- WP: Override/update the_content from database with the publicly echo the_content
- How to implement Mapbox GL JS with a custom Gutenberg block in FSE?
- Is there a way to assign a default Category to a Post when the user creates a new Post?
- Event when Modal is opened/visible
- Why is the Gutenberg editor not recognizing my updates?
- is_user_logged_in() doesn’t work after custom login and redirect