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. If you’re the use of Gutenberg to create content material, you use the one’s blocks or custom blocks which are provided via WordPress plugins you put in on your website.
What Is React?
In front-give up development, the least performant things you do are studying and writing from the DOM. A very hard aspect to do, constantly across browsers, is referencing and updating the DOM. React offers a better device for this, with the aid of enforcing a reactive programming version and a virtual DOM abstraction.
How Is React Being Used in Gutenberg?
React is a library for growing reusable components. Because they’re reusable, we are able to compose interfaces out of additives. It is an open-source mission created at Facebook.
Everything is a block. Text, pics, galleries, widgets, shortcodes, and even chunks of custom HTML, irrespective of if it’s introduced by means of plugins or otherwise. You have to only should 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. Gutenberg is created with React, so every block is composed of 1 or greater components.
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 the identical, 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 center or plugins, you by no means want to make your very own block types.
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 all you actually do need to realize are some functions: wp.CreateElement, which creates HTML and setAttribute(), which is used to replace your block attributes.
I suggest going thru the Creating Blocks section of the Gutenberg guide after which looking over the examples repo in addition to the example code from the WordCamp Miami 2018 Gutenberg workshop. That’s all code you can use without digging into React in any respect.
If you need to make simple easy blocks, maybe with one or controls, then you definitely do now 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. 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 begin 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.