Act as if what you do makes a difference. It does. – William James

How to Load React in WordPress themes

How to Load React in WordPress themes

Since WordPress version 5.0 the most popular CMS now ships with it the most popular javascript front-end library. While it is far too soon to start singing goodbye to jQuery which has been used in WP for years and is part of both the core of WP and nearly every theme and plugin, React is going to play an increasingly big role in the WordPress landscape.

In WordPress the whole React and ReactDOM libraries are exported into an object named wp.element. This is a global window element. And if you’ve worked with React before you know this is bit unusual compared to how React apps normally are setup. The big difference is that in a normal React app we import React, whereas in WP we don’t. Same for ReactDOM, as both are already loaded.

Tooling differences when using React in WordPress

The other major difference in working with React in WordPress is the tooling. And for those who already work with WP but are not as experienced in React this difference might actually make using React and ReactDOM easier. Normally React apps are built using various tools such as Create React App or other bundles of CLI tools. These tools generally don’t work with WP because need to avoid importing React.

Leave a Reply

Your email address will not be published. Required fields are marked *

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

admin

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

admin