<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: David Rodríguez </title>
    <description>The latest articles on DEV Community by David Rodríguez  (@davidjguru).</description>
    <link>https://dev.to/davidjguru</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F124245%2F04d1a876-751d-4771-908c-75177de7214c.jpg</url>
      <title>DEV Community: David Rodríguez </title>
      <link>https://dev.to/davidjguru</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/davidjguru"/>
    <language>en</language>
    <item>
      <title>Learning React (I): Three HelloWorld examples</title>
      <dc:creator>David Rodríguez </dc:creator>
      <pubDate>Tue, 03 May 2022 18:23:36 +0000</pubDate>
      <link>https://dev.to/davidjguru/learning-react-i-three-helloworld-examples-276</link>
      <guid>https://dev.to/davidjguru/learning-react-i-three-helloworld-examples-276</guid>
      <description>&lt;ul&gt;
&lt;li&gt;Header Image from Unsplash, &lt;a href="https://unsplash.com/@markusspiske" rel="noopener noreferrer"&gt;user Markus Spiske, @markusspiske&lt;/a&gt;.
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Introduction.&lt;/li&gt;
&lt;li&gt;Hello World using a single HTML file.&lt;/li&gt;
&lt;li&gt;Hello World splitting files.&lt;/li&gt;
&lt;li&gt;Hello World building a local environment.&lt;/li&gt;
&lt;li&gt;
Read More.

&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1. Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React or React.js&lt;/a&gt; is one of the most popular resources for creation of Interfaces based in JavaScript&lt;/strong&gt;, for &lt;a href="https://geekflare.com/single-page-applications/" rel="noopener noreferrer"&gt;SPA (Single Page Application)&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/Introduction" rel="noopener noreferrer"&gt;PWA (Progressive Web Application)&lt;/a&gt; or maybe &lt;a href="https://medium.com/airbnb-engineering/isomorphic-javascript-the-future-of-web-apps-10882b7a2ebc" rel="noopener noreferrer"&gt;“Isomorphic JavaScript”&lt;/a&gt; (that is, the execution part in server and part in client). React was created by Facebook and Open-sourcered in 2013, &lt;a href="https://github.com/facebook/react" rel="noopener noreferrer"&gt;available since then from repositories&lt;/a&gt; and libraries that can be fully integrated into your project.&lt;/p&gt;

&lt;p&gt;In my case, I haven't used React until recently and due to the needs of a project: I'm working with &lt;a href="https://www.acquia.com/resources/decoupled-drupal" rel="noopener noreferrer"&gt;decoupled Drupal&lt;/a&gt; models (headless) and the frontend had been created with React. I had used Angular for some pet-projects, so I had some basic SPA concepts already known. But now &lt;strong&gt;I'm working with React and I wanted to share some basic steps&lt;/strong&gt; that can be executed to better understand some fundamental React concepts.  &lt;/p&gt;

&lt;p&gt;I thought I'd put together some examples in a progressive way, from less to more, in a series of articles focused on working with React as a frontend technology on a daily basis. &lt;strong&gt;So please, read, share and take advantage of everything you can find useful.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;2. Hello World using a single HTML file&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Our first example is the most basic case that you can implement in your own environment without any configuration or package manager. &lt;strong&gt;It only requires a single HTML file, a browser to open the HTML file and some external links to get the React resources&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How does it work?&lt;/strong&gt; Well in order to create a new basic React example we only need some basic resources: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/docs/getting-started.html" rel="noopener noreferrer"&gt;The basic React Library&lt;/a&gt;: The essential JavaScript library for building user interfaces. &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/docs/react-dom.html" rel="noopener noreferrer"&gt;The basic React Dom Library&lt;/a&gt;: A package that provides DOM specific methods and resources.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://babeljs.io/docs/en/index.html#jsx-and-react" rel="noopener noreferrer"&gt;The Babel Tool&lt;/a&gt;: Babel is a compiler / transpiler that converts code to compatible versions. Also works with React and &lt;a href="https://reactjs.org/docs/introducing-jsx.html" rel="noopener noreferrer"&gt;its native syntax, JSX&lt;/a&gt;. You write code in JSX and Babel will convert your code into usable JavaScript. That’s all. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Firstly&lt;/strong&gt;, we’ll create a new single and basic HTML file, called &lt;code&gt;react_hello_world.html&lt;/code&gt; with an basic scheme of HTML tags inside, something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
           &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;My custom title&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
         &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Hello World!&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;  
  &lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Not difficult, right?&lt;/strong&gt; This kind of file can be created in your favorite text editor or in your selected IDE. And then you’ll only need to open the file with your browser and see the Hello World message in screen: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy7gnm17l8bzndzzu004h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy7gnm17l8bzndzzu004h.png" alt="Hello World generated in a single HTML file."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Remember:&lt;/strong&gt; If you don't understand the above lines very well, it might be interesting for you to know &lt;a href="https://html.com/" rel="noopener noreferrer"&gt;the basics of HTML&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Secondly&lt;/strong&gt;, We’ll add the external React resources, by using the common HTML tag &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;. Doing so we’ll requesting all the necessary tooling: &lt;strong&gt;React (basic)&lt;/strong&gt;, &lt;strong&gt;React Dom (to operate with DOM in HTML)&lt;/strong&gt; and &lt;strong&gt;Babel (the Compiler / Transpiler for JSX, the React syntax)&lt;/strong&gt;. We’ll include the new links in our &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Load React basic resources. --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.21.1/babel.min.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Lastly&lt;/strong&gt;, We’ll create a new &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tag which will be just like our new &lt;em&gt;“entry point”&lt;/em&gt; for the new React component: we’ll hook our custom element from this item, and we will call it “root” inside the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; section as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"root"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now we have to add the code of our new custom React Component, our salutation. We can see the next three parts in the snippet below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Loading our new React component. --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/babel"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;!--&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;Description&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="o"&gt;--&amp;gt;&lt;/span&gt;
   &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Greeting&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;!--&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;Message&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="o"&gt;--&amp;gt;&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="nx"&gt;generated&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;unique&lt;/span&gt;               &lt;span class="nx"&gt;HTML&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;     &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;!--&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;Render&lt;/span&gt; &lt;span class="nx"&gt;Instructions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="o"&gt;--&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Greeting&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The Description:&lt;/strong&gt; We’ve created a class extending React.Component.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Message to render:&lt;/strong&gt; We’ve added a string within a return function.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Render instructions:&lt;/strong&gt; We’ve used the ReactDOM library in order to launch the render of our new component/class, hooking the new item inside the &lt;code&gt;id=”root”&lt;/code&gt; created &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tag. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Finally, our HTML file will look:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Document title&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Hello World!&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"root"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
       &lt;span class="c"&gt;&amp;lt;!-- Load React. --&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.21.1/babel.min.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;

       &lt;span class="c"&gt;&amp;lt;!-- Load our React component. --&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text/babel"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
         &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Greeting&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="nx"&gt;generated&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;unique&lt;/span&gt; &lt;span class="nx"&gt;HTML&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;         &lt;span class="p"&gt;}&lt;/span&gt;
       &lt;span class="p"&gt;}&lt;/span&gt;

       &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
       &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Greeting&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
       &lt;span class="p"&gt;);&lt;/span&gt;
     &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;  

    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;  
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We’ve already finished! We are done! &lt;strong&gt;remember these three basic steps we have done (it will be the core of any basic development with React)&lt;/strong&gt;: we have created a class/component, we have asked it to render and we have indicated from which element of the DOM (HTML) we wanted to load the new component. &lt;strong&gt;That's all!&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;And now if you open the file with your browser using right click from mouse or line command (you can use &lt;code&gt;$ xdg-open react_hello_world.html&lt;/code&gt; ) you’ll see the new version of our Greetings file:   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fepa9vpp5hpz2i39kwfc5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fepa9vpp5hpz2i39kwfc5.png" alt="Hello World from an unique HTML file with React integration."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;3. Hello World splitting files&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We have now created our first "Hello World" with React in a unified way, in a single file, loading the external resources and generating an output to a &lt;em&gt;"root"&lt;/em&gt; element. But this is not usually the daily reality, where we work with separate files of a different nature.   &lt;/p&gt;

&lt;p&gt;To make this approach more "real", we are going to use a simple and intuitive platform that allows us to start separating resources. We will try with &lt;a href="https://codepen.io" rel="noopener noreferrer"&gt;CodePen.io&lt;/a&gt;, an online platform for testing code snippets especially focused on HTML / CSS / JavaScript for web.  &lt;/p&gt;

&lt;p&gt;Enable an account and create a new snippet / pen. Then we only have to set some basic configurations in our new snippet / pen: &lt;strong&gt;select Babel as JavaScript Preprocessor&lt;/strong&gt; (remember we’re using JSX syntax and It’s not pure JavaScript) and add external scripting for the basic &lt;code&gt;react&lt;/code&gt; library and the &lt;code&gt;react-dom&lt;/code&gt; library (as in the previous example).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://unpkg.com/react/umd/react.development.js" rel="noopener noreferrer"&gt;https://unpkg.com/react/umd/react.development.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://unpkg.com/react-dom/umd/react-dom.development.js" rel="noopener noreferrer"&gt;https://unpkg.com/react-dom/umd/react-dom.development.js&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdchq5st210cxg6kyc37f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdchq5st210cxg6kyc37f.png" alt="Configuring options in CodePen for creating React Examples."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CodePen will load the scripts in our code before rendering the snippet. &lt;strong&gt;There we go&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Firstly&lt;/strong&gt;, in the HTML tab we’ll include a basic original &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; working as &lt;em&gt;root&lt;/em&gt; element for our React example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"root"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Secondly&lt;/strong&gt;, we’ll build the JSX snippet in the JS tab. In this case, we’re using latest versions of React and as you can see, we have some differences with respect to the first example in this post. &lt;strong&gt;Let’s see the code:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRoot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Button&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;World&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="nx"&gt;generated&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nx"&gt;different&lt;/span&gt; &lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What’s happening here?&lt;/strong&gt; Well, now we’re using &lt;code&gt;ReactDOM.createRoot&lt;/code&gt;  instead of &lt;code&gt;ReactDOM.render&lt;/code&gt; (as in the first case), due to changes in ReactDOM versions. This is something that has changed in the latest versions: &lt;code&gt;ReactDOM.render&lt;/code&gt; is no longer supported in React 18, but I have kept the two different examples for different versions of React (15.x vs 18.x). You can read more info about it here: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://blog.saeloun.com/2021/07/15/react-18-adds-new-root-api.html" rel="noopener noreferrer"&gt;https://blog.saeloun.com/2021/07/15/react-18-adds-new-root-api.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html" rel="noopener noreferrer"&gt;https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Finally&lt;/strong&gt;, we’ll add some (very basic) styles in order to see the rendering. We’ve add some colors to the specific &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; and the message in screen:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The three tabs will load a React example using a Hello World message in our CodePen board, showing in console the internal structure:   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm2crzxi193e32v862wq4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm2crzxi193e32v862wq4.png" alt="Hello World message rendered from a Codepen board."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;4. Hello World building a local environment&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Well, ok. We’ve built a first example using an unique HTML file, then we’ve built another Hello World example using separate files in an external environment (CodePen.io) and now we have to take another step: We are going to build a new example from a local environment, which involves the initial and basic installation and configuration of a local development environment for React. &lt;/p&gt;

&lt;p&gt;This is really the interesting part of this block: &lt;em&gt;What do we need to work locally with React?&lt;/em&gt; &lt;strong&gt;Let's see&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Building up your local environment
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Install Node.js (Ubuntu)
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt; is an execution evironment for executing JavaScript from the server side. You will need to enable Node in your environment in order to work with React. In Ubuntu, you can install Node.js just by command line from the official repositories, by doing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nv"&gt;$ $ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt upgrade &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;nodejs &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But it can install an older version of Node.js… so we’ll need to execute an update..&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Install NPM // Update NPM (if needed) // Or install Yarn
&lt;/h4&gt;

&lt;p&gt;We’ll need a package manager in order to resolve dependencies, so we can use &lt;a href="https://github.com/npm/cli" rel="noopener noreferrer"&gt;npm&lt;/a&gt; and yarn (npm-compatible).  Using npm we’ll be able to update the current Node.js version to the latest stable version or non-stable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;npm
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;n latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs3n3zwphfngclnirwtdi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs3n3zwphfngclnirwtdi.png" alt="Updating nodejs with npm."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For updating npm as package manager, you can run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; npm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will install or just will update your current npm version and resources: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbexbl5j8k8t74zlov8tj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbexbl5j8k8t74zlov8tj.png" alt="npm update with global flag."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://yarnpkg.com/" rel="noopener noreferrer"&gt;Yarn&lt;/a&gt; is another JavaScript package manager and is compatible with npm. It helps us automatize installing, updating, configuring, and removing npm packages, speeding up the installation process.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;curl &lt;span class="nt"&gt;-sS&lt;/span&gt; https://dl.yarnpkg.com/debian/pubkey.gpg | &lt;span class="nb"&gt;sudo &lt;/span&gt;apt-key add -
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"deb https://dl.yarnpkg.com/debian/ stable main"&lt;/span&gt; | &lt;span class="nb"&gt;sudo tee&lt;/span&gt; /etc/apt/sources.list.d/yarn.list
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--no-install-recommends&lt;/span&gt; yarn

&lt;span class="nv"&gt;$ &lt;/span&gt;yarn &lt;span class="nt"&gt;--version&lt;/span&gt;
1.22.18 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Install // Use create-react-app tool
&lt;/h4&gt;

&lt;p&gt;Create React App is a very-comfortable tool for creating new apps based in React in your local environment. It works on macOS, Windows and Linux and you don’t need to install and configure resources as Babel or webpack: they are preconfigured! You’ll need to have Node &amp;gt;= 14.0.0 and npm &amp;gt;= 5.6 in your environment.&lt;/p&gt;

&lt;p&gt;We can install create-react-app as a new dependency by using npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; create-react-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will install the package as a global resource with &lt;code&gt;-g&lt;/code&gt; flag. This will do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;create-react-app &lt;span class="nt"&gt;--version&lt;/span&gt;
  5.0.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this will be ok and can be used for initial testing, &lt;strong&gt;but its creators recommend us to uninstall the global resource in order to force that we’ll use the latest version of create-react-app per specific project&lt;/strong&gt;, just like a dependency. So use the next two versions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm uninstall &lt;span class="nt"&gt;-g&lt;/span&gt; create-react-app
&lt;span class="o"&gt;[&lt;/span&gt;...]
&lt;span class="nv"&gt;$ &lt;/span&gt;yarn global remove create-react-app 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Creating the component
&lt;/h3&gt;

&lt;p&gt;Now we’re going to create our first Hello World React app in a local environment using scaffolding generated by the create-react-app package. And we’ll also use &lt;a href="https://nodejs.dev/learn/the-npx-nodejs-package-runner" rel="noopener noreferrer"&gt;npx&lt;/a&gt;. npx is a package runner tool that comes with npm.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npx create-react-app hello-world
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;hello-world
&lt;span class="nv"&gt;$ &lt;/span&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But you can use alternatives like npm or yarn:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm init react-app hello-world-2
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;hello-world-2
&lt;span class="nv"&gt;$ &lt;/span&gt;npm start
&lt;span class="o"&gt;[&lt;/span&gt;...] 
&lt;span class="nv"&gt;$ &lt;/span&gt;yarn create react-app hello-world-3
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;hello-world-3
&lt;span class="nv"&gt;$ &lt;/span&gt;yarn start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fact is that after launching the start, the new application will be launched via the pre-configured web server and &lt;strong&gt;the application will be deployed directly through port 3000&lt;/strong&gt; (be careful if you have it in use), opening from your favorite browser:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy223sclrcp2ubs6anugb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy223sclrcp2ubs6anugb.png" alt="Deploying in browser a new React app."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we have a new React App created with scaffolding. &lt;strong&gt;…But what do we have inside?&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Inspecting the rendered component
&lt;/h3&gt;

&lt;p&gt;And at the end, we can open the just created folder with our new React App “Hello World” and see how the scaffolding provided by &lt;code&gt;create-react-app&lt;/code&gt; is. Open now the created folder in your favorite IDE // Editor and see the content within the project:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F05tay5d2aj7pzf8rouj5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F05tay5d2aj7pzf8rouj5.png" alt="React App basic resources from main folder."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you can see all the dependencies downloaded (folder “node_modules”), the public folder with all the resources for the web server, the &lt;code&gt;src&lt;/code&gt; folder with the code of our app and other files like a basic gitignore (create-react-app starts git as control version system in the new folder) and the files for registering dependencies (&lt;code&gt;package-lock.json&lt;/code&gt; and &lt;code&gt;package.json&lt;/code&gt;). Among all these resources, there some important files that we’ve to review: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;index.html&lt;/strong&gt;: The HTML main file, with a div called “root” as entrypoint for our app.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;App.js&lt;/strong&gt;: Our new component, described in JSX syntax and with a central message for screen.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;index.js&lt;/strong&gt;: The file loading the App component and charging the rendering from the root div present in index.html file. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We’ll change the central message placed in App.js and we’ll put this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Hello World! this is a React App from a local environment.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now just saving the change and reloading the URL in browser you’ll see our custom updated message. &lt;strong&gt;That's all!    We’ve done it!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1bpikvukpx6jdzltfqko.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1bpikvukpx6jdzltfqko.png" alt="Customizing message in the basic React App."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To conclude&lt;/strong&gt;, we need to review all the little things we have practiced throughout this article on getting started with React. We wanted to create "Hello World" cases and almost without realizing it, we got a great snapshot (the big picture) of the fundamentals of React.&lt;/p&gt;

&lt;p&gt;You can download the last two examples of this post from the &lt;a href="https://github.com/davidjguru/react-examples" rel="noopener noreferrer"&gt;Github repository&lt;/a&gt;: use the single HTML file and for the React local App, just run &lt;code&gt;$ npm install&lt;/code&gt; (this will download all the node_modules folder for dependencies) and then &lt;code&gt;$ npm start&lt;/code&gt; in order to run and launch the App in server + browser. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What do we know now?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The most basic resources for developing React App: The react library, the react-dom library and the Babel Transpiler (remember you’re using JSX syntax). &lt;/li&gt;
&lt;li&gt;Basic resources for developing React code in a local   environment and how to install and use it:

&lt;ul&gt;
&lt;li&gt;Environment: Node.js&lt;/li&gt;
&lt;li&gt;Package Managers: npm, yarn&lt;/li&gt;
&lt;li&gt;Command Runner: npx&lt;/li&gt;
&lt;li&gt;Package for basic React Apps: create-react-app&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Scaffolding of basic React Apps using create-react-app&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Read More
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://html.com/" rel="noopener noreferrer"&gt;Basics of HTML&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.w3schools.com/html/html_basic.asp" rel="noopener noreferrer"&gt;HTML Basic Examples - WC3 Schools&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/facebook/create-react-app/blob/main/packages/cra-template/template/README.md" rel="noopener noreferrer"&gt;Getting Started with Create React App&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://create-react-app.dev/docs/getting-started" rel="noopener noreferrer"&gt;Create React App - Quick Start&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://reactjs.org/docs/add-react-to-a-website.html" rel="noopener noreferrer"&gt;Add React to a Website&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>jsx</category>
    </item>
    <item>
      <title>Erasing traces of Generator in Drupal Projects</title>
      <dc:creator>David Rodríguez </dc:creator>
      <pubDate>Fri, 01 May 2020 18:21:04 +0000</pubDate>
      <link>https://dev.to/davidjguru/erasing-traces-of-generator-in-drupal-projects-1cdh</link>
      <guid>https://dev.to/davidjguru/erasing-traces-of-generator-in-drupal-projects-1cdh</guid>
      <description>&lt;ul&gt;
&lt;li&gt;Image from Unsplash, &lt;a href="https://unsplash.com/@kimgorga"&gt;user Kim Gorga, @kimgorga&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1-Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;It's very common, when you're working on projects, to receive a ticket from the client requesting the removal of signals that make it easier to know with which technology the website has been generated.&lt;br&gt;&lt;br&gt;
Normally, the client performs a security audit to the platform and from there several frequent items are generated: update the core to keep up to date in security, Normally, the client performs a security audit to the platform and from there several frequent items are generated: updating the core to keep up to date in security (being aligned with &lt;a href="https://www.drupal.org/security"&gt;https://www.drupal.org/security&lt;/a&gt; in core and patches), as well as some common places, which often go through hiding sensitive information to possible attackers.  &lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;2-Premise&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Okay, but are there ways to completely hide the fact that the website was built using Drupal?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Well, no. In fact, anyone can open the code inspector console of a decent browser (Chrome, Firefox) and when in doubt as to whether they are looking at a Drupal-based site, call up the Drupal JavaScript object. And it will always respond with its associated properties and methods: &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VLRbzRcL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/wewk7p2gx23o7z26lb7x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VLRbzRcL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/wewk7p2gx23o7z26lb7x.png" alt="Getting the Global Drupal Object from a Drupal site" width="783" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And usually a quick scan of their associated JavaScript libraries will reveal names like drupal.js, which makes it difficult to hide the technology (sometimes we even get the request to rename these JavaScript libraries to hide the keyword 'drupal'...).   &lt;/p&gt;

&lt;p&gt;Having explained this, it is true that we cannot hide the generator from a human eye, but perhaps we can help hide it (on a basic level) from the machines. Some tactics even include offering an adulterated robots.txt structure to simulate another technology and make crawlers believe that it's another platform (WordPress for example), and building a honeypots subsystem internal to the spoofed addresses to detect spying... but I think that's already another topic for another article. &lt;/p&gt;
&lt;h2&gt;
  
  
  3-Targets
&lt;/h2&gt;

&lt;p&gt;Here (having stated this former important premise) I would just like to collect some solutions to hide meta-information in some parts of the Drupal installation when you wanna obfuscate that you are running a Drupal installation: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1- First of all:&lt;/strong&gt; hide the "Generator" meta tag from the 'head' section of a document - page delivered to the web browser:   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w0u9hpKL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/zxbpzzl3f5jzf7fvp1gc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w0u9hpKL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/zxbpzzl3f5jzf7fvp1gc.png" alt="Metatags and info in Drupal head section" width="800" height="311"&gt;&lt;/a&gt;   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2- Then:&lt;/strong&gt; I would also like to remove from the server -&amp;gt; client response headers a specific Drupal header called X-Generator, which delivers the server version of Drupal:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L-SNfG0o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/zpq3ae9tpqtxfqb9ax8g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L-SNfG0o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/zpq3ae9tpqtxfqb9ax8g.png" alt="Drupal X-Generator info in Response Headers" width="800" height="454"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;X-Generator is created in Drupal installations and &lt;a href="https://webtechsurvey.com/response-headers/x-generator/"&gt;fullfilled with info about the system version&lt;/a&gt; (xhr is a shortened way for XMLHttpRequest).&lt;/p&gt;

&lt;p&gt;The tag is setted from &lt;a href="https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21EventSubscriber%21ResponseGeneratorSubscriber.php/class/ResponseGeneratorSubscriber/8.8.x"&gt;the class ResponseGeneratorSubscriber&lt;/a&gt; present in the Core of Drupal:   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NCXBG4iQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/mnzc4ux99ewdxqjeaaos.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NCXBG4iQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/mnzc4ux99ewdxqjeaaos.png" alt="Drupal X-Generator setted by an Event Subscriber from the Drupal Core" width="800" height="372"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Is managed through an onRespond() function that follows the Drupal event subscription pattern (itself based on Symfony event management):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;  &lt;span class="cd"&gt;/**
   * Sets extra X-Generator header on successful responses.
   *
   * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
   *   The event to process.
   */&lt;/span&gt;
  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;onRespond&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;FilterResponseEvent&lt;/span&gt; &lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;isMasterRequest&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getResponse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// Set the generator in the HTTP header.&lt;/span&gt;
    &lt;span class="k"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$version&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;explode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;\Drupal&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;VERSION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'X-Generator'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Drupal '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$version&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;' (https://www.drupal.org)'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;4- Tasks&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To make the hides of the information shown in the previous section, we will use a combined action of the paradigms that currently exist within Drupal: the procedural of the Hooks system (vestigial) and the OOP of the event subscription systems. We are going to use both techniques in a combined way.   &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4.1- Building a custom module&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We're going to create a new custom module for our goals, I will call it "&lt;em&gt;headers_manager&lt;/em&gt;" -in a clear show of creativity, of course- and I will create the basic resource:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;headers_manager
   \_headers_manager.info.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And as info:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Headers Manager&lt;/span&gt;
&lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Custom Module created to manage meta-info from head and headers.&lt;/span&gt;
&lt;span class="na"&gt;package&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Workshop&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Drupal'&lt;/span&gt;
&lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;module&lt;/span&gt;
&lt;span class="na"&gt;core&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;8.x&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;4.2- Building a Hook&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Next, we're going to work over the metatags in the &lt;/p&gt; section of the HTML content, for wich we'll need a Drupal Hook, something called &lt;a href="https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21theme.api.php/function/hook_page_attachments_alter/8.8.x"&gt;&lt;strong&gt;hook_page_attachments_alter&lt;/strong&gt;&lt;/a&gt;, just a procedural function to change assets to a page before the rendering phase. 

&lt;p&gt;According to its own documentation: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Use this hook when you want to remove or alter attachments on the page, or add attachments to the page that depend on another module's attachments (this hook runs after hook_page_attachments()&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So we're going to use the hook within a .module file. In the hook only we'll review the html_head charged as attachment to every page sended to render. And if the keyname of the attachment is equals to the meta tag that we're looking for, then we'll unset the value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cd"&gt;/**
 * Implements hook_page_attachements_alter().
 * @param array $attachments
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;headers_manager_page_attachments_alter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nv"&gt;$attachments&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$attachments&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'#attached'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'html_head'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$key&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$attachment&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$attachment&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'system_meta_generator'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;unset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$attachments&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'#attached'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s1"&gt;'html_head'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now our custom module has:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;headers_manager
  \_headers_manager.module
   \_headers_manager.info.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;4.3- Building an Event Subscriber&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The nex step is disable the X-Generator header in responses from the Server. For this, we'll build a new EventSubscriber as in the original case where the header is attached (has been seen before). &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First&lt;/strong&gt;, we're creating a new service for our Subscribe in a .service.yml file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;headers_manager_response_header&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Drupal\headers_manager\EventSubscriber\HeadersManagerResponseSubscriber&lt;/span&gt;
    &lt;span class="na"&gt;tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;event_subscriber&lt;/span&gt; &lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Then&lt;/strong&gt;, we'll create  the Subscriber using a path like &lt;code&gt;headers_manager/src/EventSubscriber/HeadersManagerResponseSubscriber.php&lt;/code&gt;.&lt;br&gt;
In our new Subscriber class file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Drupal\headers_manager\EventSubscriber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Symfony\Component\EventDispatcher\EventSubscriberInterface&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Symfony\Component\HttpKernel\Event\FilterResponseEvent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Symfony\Component\HttpKernel\KernelEvents&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cd"&gt;/**
 * Response subscriber to remove thes X-Generator header tag.
 */&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HeadersManagerResponseSubscriber&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;EventSubscriberInterface&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="cd"&gt;/**
   * Remove extra X-Generator header on successful responses.
   *
   * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
   *   The event to process.
   */&lt;/span&gt;
  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;HeadersManagerOptions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;FilterResponseEvent&lt;/span&gt; &lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getResponse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'X-Generator'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="cd"&gt;/**
   * {@inheritdoc}
   */&lt;/span&gt;
  &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getSubscribedEvents&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$events&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;KernelEvents&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;RESPONSE&lt;/span&gt;&lt;span class="p"&gt;][]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'HeadersManagerOptions'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$events&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So we'll capture events from the Kernel, and specifically we are asking for the event RESPONSE, assigning it in an array the name of the function that is responsible for interacting with the event, and a figure that represents the 'weight' as an order of priority of execution of our event alteration. Thus with a low weight, we ensure that our alteration is executed just after the attachment of X-Generator in the previous subscriber. Using a low value we avoid that our change is executed before the loading of the header.&lt;/p&gt;

&lt;p&gt;Finally our module will have the internal structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;headers_manager
  \_headers_manager.info.yml
   \_headers_manager.module
    \_headers_manager.services.yml
     \_src
         \_EventSubscriber
             \_HeadersManagerResponseSubscriber.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And so with this custom module, after enabling it in our Drupal installation, it will process the pages delivered by the server from the hook and from the event subscriber to remove the information we have configured. &lt;/p&gt;

&lt;p&gt;You can download the custom module &lt;a href="https://gitlab.com/davidjguru/drupal-custom-modules-examples/-/tree/master/headers_manager"&gt;here, from my Gitlab profile&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Read more about Events and Subscribers (Symfony, Drupal)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here you can find much more information about the concepts previously exposed and consult a multitude of use cases and examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.drupal.org/docs/8/modules/d8-rules-essentials/for-developers/events"&gt;DOC: Use of events in the Drupal Rules module&lt;/a&gt;.
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.drupal.org/docs/8/creating-custom-modules/subscribe-to-and-dispatch-events"&gt;DOC: Subscribe to and dispatch events (Drupal Event Systems Overview)&lt;/a&gt;.
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://symfony.com/doc/current/event_dispatcher.html"&gt;DOC Event Dispatcher examples in the Symfony documentation&lt;/a&gt;.
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://symfony.com/doc/current/components/http_kernel.html"&gt;DOC: The HttpKernel in Symfony&lt;/a&gt;.
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://symfony.com/doc/current/reference/events.html#kernel-events"&gt;DOC: The KernelEvents class in Symfony&lt;/a&gt;.
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://api.drupal.org/api/drupal/vendor%21symfony%21event-dispatcher%21EventSubscriberInterface.php/interface/EventSubscriberInterface/8.2.x"&gt;DOC: The EventSubscriberInterface from Symfony in Drupal&lt;/a&gt;.
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>drupal</category>
      <category>drupal8</category>
      <category>drupal9</category>
      <category>symfony</category>
    </item>
    <item>
      <title>Managing configuration objects in Drupal 8|9 for Migrations </title>
      <dc:creator>David Rodríguez </dc:creator>
      <pubDate>Wed, 08 Apr 2020 01:54:42 +0000</pubDate>
      <link>https://dev.to/davidjguru/managing-configuration-objects-in-drupal-8-9-for-migrations-4fij</link>
      <guid>https://dev.to/davidjguru/managing-configuration-objects-in-drupal-8-9-for-migrations-4fij</guid>
      <description>&lt;ul&gt;
&lt;li&gt;Image from Unsplash, &lt;a href="https://unsplash.com/@drc1948"&gt;user Denis Chick, @drc1948&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Well, I was working in some migrations and I thought that it would be interesting to gather some tools for working with configuration objects, especially from the point of view of Drupal migrations based on a treatment as configuration (not as code).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You can learn the differences between both approaches (Migration as code or Migration as configuration) in this article:&lt;/strong&gt; &lt;a href="https://www.therussianlullaby.com/blog/thinking-about-drupal-migrations-examples/"&gt;https://www.therussianlullaby.com/blog/thinking-about-drupal-migrations-examples&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But maybe the most important point right now it's that &lt;strong&gt;if you decide to manage a Drupal Migration as a Configuration entity, then, you'll create a new active configuration Object in your Drupal Installation&lt;/strong&gt;. This change all the whole workflow of a single migration as code, due to (now), you're putting your new migration inside the processes and workflows of the Configuration Management System of Drupal. Ok? Let's see. &lt;/p&gt;

&lt;p&gt;I'm working in a basic migration example using a classical .csv file as datasource. I'm building the basic scaffolding in a custom module, with the next structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/project/web/modules/custom/  
                     \__migration_csv_module/  
                         \__migration_csv_module.info.yml
                          \__csv/
                               \_migration_csv_articles.csv
                           \__config/
                              \__install/
                                 \__migrate_plus.migration.csv_import.yml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In order to run the migration using drush commands for migrations, First I will have to load the new active configuration object. Ok. &lt;/p&gt;

&lt;p&gt;You can use the User Interface in path: &lt;br&gt;
/admin/config/development/configuration/single/export   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qoUa0H-_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tdc4vlc5552q335o5epf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qoUa0H-_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tdc4vlc5552q335o5epf.png" alt="Loading a migration config object"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And finally, if I decide stop the migration and delete the results, I have to eliminate this config object. Let's see some tactics. &lt;/p&gt;
&lt;h2&gt;
  
  
  Auto delete the active config object
&lt;/h2&gt;

&lt;p&gt;When you're working with Drupal migrations as config, then you have to ensure the delete of the new migration-related config object in your Drupal System. &lt;strong&gt;You have to declare your own custom module as a forced dependency of the migration&lt;/strong&gt;, and so when you disabled the module, then this config object will disappear.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I mean: file&lt;/strong&gt; migrate_plus.migration.article_csv_import.yml&lt;br&gt;&lt;br&gt;
with content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;uuid&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;1bcec3e7-0a49-4473-87a2-6dca09b91aba&lt;/span&gt;
&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;article_csv_import&lt;/span&gt;
&lt;span class="na"&gt;label&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Migrating&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;articles'&lt;/span&gt;
&lt;span class="na"&gt;langcode&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;en&lt;/span&gt;
&lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;dependencies&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;enforced&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;module&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;migration_csv_module&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Reviewing configuration objects
&lt;/h2&gt;

&lt;p&gt;You can use this contrib module in order to test and review config:&lt;br&gt;&lt;br&gt;
&lt;a href="https://www.drupal.org/project/config_inspector"&gt;Configuration Inspector Module&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
I didn't know it, but in the context of &lt;a href="https://www.drupal.org/project/humanstxt/issues/3123129"&gt;this issue&lt;/a&gt;, &lt;a href="https://www.drupal.org/u/pcambra"&gt;Pedro Cambra&lt;/a&gt; recommended me to use it.  With this module you'll can review a config: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6B7CEWAX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cst9f8dexdrw8alm12gc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6B7CEWAX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cst9f8dexdrw8alm12gc.png" alt="Configuration Inspector Module Feedback"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Deleting configuration objects
&lt;/h2&gt;

&lt;p&gt;Also you can use the classical tools from drush and drupal console (both are Drupal CLIs) in order to delete some config objects.&lt;/p&gt;
&lt;h3&gt;
  
  
  Using drush
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;:~$&lt;/strong&gt; drush config-delete 'migrate_plus.migration.csv_import'&lt;br&gt;&lt;br&gt;
&lt;strong&gt;:~$&lt;/strong&gt; drush config:delete "migrate_plus.migration.csv_import"&lt;br&gt;&lt;br&gt;
&lt;strong&gt;:~$&lt;/strong&gt; drush cdel migrate_plus.migration.csv_import      &lt;/p&gt;
&lt;h3&gt;
  
  
  Using Drupal Console
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;:~$&lt;/strong&gt; drupal config:delete active "mymigration.active_config_object"&lt;br&gt;&lt;br&gt;
&lt;strong&gt;:~$&lt;/strong&gt; drupal cd active mymigration.active_config_object     &lt;/p&gt;

&lt;p&gt;You can use this contrib module from &lt;a href="https://www.drupal.org/u/gnikolovski"&gt;Goran Nikolovski&lt;/a&gt;:&lt;br&gt;&lt;br&gt;
&lt;a href="https://www.drupal.org/project/config_delete"&gt;Config Delete Module&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
Just install this module and visit the following page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;/admin/config/development/configuration/delete&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then you'll be able to select the Config Object and delete it.&lt;/p&gt;

</description>
      <category>drupal</category>
      <category>drupal8</category>
      <category>drupal9</category>
      <category>drupalmigrations</category>
    </item>
  </channel>
</rss>
