How to get data from WordPress $wpdb into React Gutenberg Blocks Frontend?

I am using $ wpdb to do a mysql query and get the data from a php file.

$  results = $  wpdb->get_results("SELECT * FROM table_name");  

Now, I have registered a Gutenberg block with the wordpress api..

the component is a .js file, which uses (WordPress React) under the hood:

import { registerBlockType } from "@wordpress/blocks"; import { __ } from "@wordpress/i18n"; import edit from "./pruefungenEdit";  registerBlockType("mytheme-blocks/pruefungen", {     title: __("Pruefungen Block", "mytheme-blocks"),     description: __("Display a Table of exams", "mytheme-blocks"),     category: "mytheme-category",     icon: {         background: "#f03",         foreground: "#fff",         src: "dashicons-database",     },     keywords: [__("pruefungenBlock", "mytheme-blocks")],     edit: edit,     save: () => {         return <p>Test</p>;     }, }); 

This is my React component that I use for above edit() function:

import { Component } from "@wordpress/element"; import { withSelect } from "@wordpress/data"; import { __ } from "@wordpress/i18n";  class PruefungenEdit extends Component {      render() {         //where to get the data from the query in .php file??         return <div>Data...</div>;     } }  export default PruefungenEdit; 

I can’t use php code obviously inside my .js react file.. I thought about setting up a small nodejs server that queries my localhost mysql table, and send that data via custom api route. THen I query that route on my react frontend and display the data… but that looks like too much workaround to me, I mean php is itself some kind of backend, does WordPress not offer that possibility to query mysql data and send it to the frontend somehow?

My question now is, how do I get the data from the php file into my gutenberg Block that I registered for the block editor frontend?

How to “modify” MediaPlaceholder / a React component?

Pardon the slightly naive question, but I’m still working on my first block, and am new to both Gutenberg and React. For lots of reasons ([hopefully] simplicity, reusability, extensibility, etc…), I’m trying to use existing stuff wherever possible. In this particular case, I’m trying to use MediaPlaceholder, but I need to make a couple of modifications:

  • I want to specify the directory that’s used, both for "upload" and for "media library"
  • I want to change the link text for "Media Library" to something else
  • I want to add a fourth option (beyond "Upload", "Media Library", and "Insert from URL")

I don’t want to do the above everywhere that MediaPlaceholder is called; only in my new plugin’s block.

The doc’s have a hook for a filter to "replace or extend" it, but I can’t find any examples of someone doing this; and, based on similar filters in other parts of the block editor, it seems like it’s mostly for "extend", and "replace" would be a PITA. Another possibility is to set the disableMediaButtons prop, and add a child with my own buttons — but that seems like it would involve a ton of repetitive code. I also looked at React’s concept of "composition", which might be what I need, but if it is, I need a much better tutorial.

Am I thinking about this the right way? If I want a "placeholder" that lets someone upload files to a specific location, or point to a URL, or do something else (the specific something else is schedule a cron job, but I don’t think that detail matters), am I best off starting with MediaPlaceholder? And, if so, what’s the Right Way to go about modifying it to do this?

Why Google Cache Showing 404 on my React Base Webpages?

My web page is client-side rendered with React. On hitting the cache, it is showing 404 instead of a rendered page.

Example Screenshot enter image description here

When I inspect the Page URL on Search Console, Its parsing and rendering my page properly on Google Index as well as on Live Test.

Example Screenshots enter image description here enter image description here

Why cache page is showing 404? Is the Client-side react is responsible? If not then what is the issue? Or will it be resolved automatically in a few days?

Note It’s my new site which recently goes live in last week.

Chrome Extension: document.querySelector(‘button’).click() is not working on button created on React

I want from extension to click the button but button click event is not working as if i use JS DOM Methods:

getElementsByClassName('button')[0].click(); // Not working //or document.querySelector('button').click(); // Not working   

The problem is that button is created either on “React.js“, so i think that causes not to happen the button click event.

Please suggest me any solution for this problem.

Thanks.

Can you react mid movement?

Alice and Belle are in combat, 30ft apart from each other.

Alice takes first turn, and readies an action; “If Belle comes within 25ft of me, I move my full speed directly away.”

On Belle’s turn, Belle says “I move 30ft right next to Alice.”

Ready states: “When the trigger occurs, you can either take your reaction right after the trigger finishes or ignore the trigger.” Does this mean that Belle is able to move next to Alice before Alice is able to react?

Breaking Up Your Move states: “You can break up your movement on your turn, using some of your speed before and after your action.” Does this mean that even if Belle moves in 5ft increments towards Alice, it is still one “move” and so Alice still cannot react before Belle is right next to them?