Type to search

Do You Need to Know React as a WordPress Developer


Do You Need to Know React as a WordPress Developer


The new WordPress content modifying machine Gutenberg can be powering the WordPress publish editor in WordPress five. Zero. Gutenberg is a “block-based totally” editor. When developing content, the whole lot is a block. If you’ve got a submit that is one paragraph, one header, and then paragraphs, that’s 4 blocks.

Gutenberg comes with a fixed or default “center” blocks — paragraph, header, recent posts, photograph, blockquote, and so forth. However, if you’re using Gutenberg to create content material, you use the one’s blocks or custom blocks provided via WordPress plugins you put in on your website.

Image result for Do You Need to Know React as a WordPress Developer

Gutenberg is a JavaScript-pushed interface. Specifically, it’s miles constructed using Facebook’s open-supply user interface library “React.” This post explains a little bit about growing your own custom blocks to be used inside the Gutenberg editor to use JavaScript. Of course, you should no longer use JavaScript to create blocks. Advanced Custom Fields (ACF) these days announced a neat-looking machine for growing custom blocks with PHP.

What Is React?

In front-give-up development, the least performant things you do are studying and writing from the DOM. A tough aspect of constantly doing across browsers is referencing and updating the DOM. React offers a better device for this to enforce a reactive programming version and a virtual DOM abstraction.

Instead of interacting with the DOM directly, for example, jQuery.Html() or jQuery.Val(), React creates a virtual illustration of the DOM. We call this a digital DOM or VDOM. The VDOM is a JavaScript object that represents the shape of the DOM. Whenever your React code communicates to React a trade in any information, the VDOM is recalculated. After that, React calculates the difference between the DOM because it existed before the change and after the exchange. Then React (virtually reaction or React Native) updates just the components of the DOM that desire modification. How it does, this doesn’t remember virtually.

How Is React Being Used in Gutenberg?

React is a library for growing reusable components. Because they’re reusable, we can compose interfaces out of additives. It is an open-source mission created on Facebook.

Everything is a block. Text, pics, galleries, widgets, shortcodes, and even chunks of custom HTML, irrespective of if it’s introduced utilizing plugins or otherwise. You only have to discover ways to master a single interface: the block interface, and you then realize how to do the whole thing. – Gutenberg Handbook

Blocks are the basic unit of Gutenberg. We compose content out of one or extra blocks.

Components are the atomic unit of React. We compose React apps out of components. For example, Gutenberg is created with React, so every block comprises 1 or greater components.

Image result for Do You Need to Know React as a WordPress Developer

It’s vital to observe, and I’ll cover this greater in this collection of posts, but Gutenberg adds a skinny abstraction layer over React. In our Gutenberg code, we’ll use up.CreateElement rather than React.CreateElement. It works identically; however, whilst React’s API changes, WordPress can determine while to support the one’s changes and provide a backward-compatibility wrapper or determined now not to.

This is right making plans for the future, but for now, it’s simply React.

Do I Need To Know React To Develop With Gutenberg?

So, this brings us to the big question, do you want to analyze React? No, you do not. None of this topic except you need to make your very own blocks. If you just need to apply the blocks provided by the center or plugins, you by no means want to make your very own block types.

No. But…
You can create a basic block without understanding tons of JavaScript. For example, take a study this fundamental instance block, simplified from the reliable Gutenberg examples:

The one component that is probably new is using up.CreateElement — in this example, it is inside the variable “el” — to create HTML. That’s a flowery manner to create an HTML element of the kind “p.” I’ll cover that during my subsequent article in this collection.

WordPress has an abstraction layer over React, so you actually need to realize some functions: wp.CreateElement, which creates HTML and setAttribute(), which is used to replace your block attributes.

I suggest going through the Creating Blocks section of the Gutenberg guide, after which looking over the examples repo and the example code from the WordCamp Miami 2018 Gutenberg workshop. That’s all code you can use without digging into React in any respect.


Yes, If…
If you need to make simple, easy blocks, maybe with one or controls, you definitely do not want to recognize React greater than those standards I cited before. But, if you want to create a more complicated block, proportion components among Gutenberg and different React apps, for instance, a wp-admin settings display or cell app in your plugin.

React is a clearly fun library to play with and talent with React is a completely marketable ability to have. But, more importantly, once you study React, you could greater without problems apprehend the greater advanced Gutenberg concepts — nation management, unit exams, and so forth.

How To Learn React For WordPress and Gutenberg
This is the beginning of a collection on React development for Gutenberg. Next time I’ll cover React basics, after which how to apply them in Gutenberg blocks. From there, we’ll make dynamic blocks, then study nation management and trying out.

I have a listing of Gutenberg developer talks on my site that you may locate usefully. In this collection, I’ll be explaining React principles. However, in case you want to analyze JavaScript and React deeply, Wes Bos and Zac Gordon have great publications on React and JavaScript to get you commenced.

Jacklyn J. Dyer

Friend of animals everywhere. Problem solver. Falls down a lot. Hardcore social media advocate. Managed a small team training dolls with no outside help. Spent high school summers creating marketing channels for Elvis Presley in Minneapolis, MN. Prior to my current job I was donating wooden trains in Hanford, CA. Spent the 80's getting my feet wet with accordians in Jacksonville, FL. Spent the 80's writing about crayon art in Africa. Managed a small team getting to know inflatable dolls in Gainesville, FL.