Create Custom Gutenberg Block – Part 3: Props and WordPress Components
The previous step in this tutorial series went through how to register a custom block, both in Javascript and in PHP. In this step we’ll learn how to use WordPress’ components for adding different kind of fields and settings. In order to utilize WordPress’ components in our block we need to first know about props. Props Props is a major feature in React and is basically a way of passing variables or functions down to other components. If you are unfamiliar with React props, you can read React’s official tutorial about this. WordPress provides some props for the edit and save functions in registerBlockType(). Inside these props we get access to critical things, such as attributes and a method to update our attributes. We’ll go through attributes in detail in the next step! So far in our block we wrote the function for edit and save like so: edit: () => { return :) }, You should get used to adding the parameter props to both edit and save, like so: edit: (props) => { re...