2

I am having trouble using ReactJs in a Wordpress plugin.

I am developing a Wordpress plugin using ReactJs. Googling only found ReactJs in a Wordpress theme, not plugin development.

MichaelP
  • 41
  • 2
  • I was able to use shortcode with the PHP-based of my plugin. Not sure how shortcode would work with React-based plugin. – MichaelP Nov 15 '15 at 15:17

1 Answers1

1

I got it working on a plugin admin page.

Started with a working PHP-based plugin setting page. Then replaced all PHP code in the setting UI page with

<div id="content"></div>

Pre-transformed the JSX. I wasn't able to get JSX transform to work on the fly. I am not if this possible in Wordpress.

Also ran into document not ready issue. This was solved by this question.

Invariant Violation: _registerComponent(...): Target container is not a DOM element

Community
  • 1
  • 1
MichaelP
  • 41
  • 2
  • I get the same error when I don't use Babel. If I include Babel, this error disappears and everything is back to normal. So, this can work if you include 3 scripts, React, ReactDOM and Babel and use "text/babel" for your app.js. Without Babel it doesn't work and I'm still trying to figure it out. – gradosevic Dec 08 '15 at 13:28