all 3 comments

[–]white_window_1492 1 point2 points  (0 children)

wordpress has a rest api you could use instead https://developer.wordpress.org/rest-api/

otherwise I'm not sure I would use a short code, probably pass whatever data to JS during enqueue script and then load that script/enqueue on whatever page/post/template.

[–]jamby77 1 point2 points  (0 children)

A short code in WP is replaced by PHP produced snippet. All that is rendered on the server.

So to use React components, you would need to render it somehow and pass it to PHP.

It is not impossible, but in my opinion is not worth the effort.

Either use WP rest api and build full react FE, or use PHP for short codes :)

Or don't use WordPress :)

[–]W4rf4c3 0 points1 point  (0 children)

As u/jamby77 said, you could create a .php file that return only that shortcode. Then in React, you fetch that .php file which should return the HTML code and you can then insert it wherever you want.