<?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>Forem: Gabriel Kalu</title>
    <description>The latest articles on Forem by Gabriel Kalu (@gabby1234).</description>
    <link>https://forem.com/gabby1234</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%2F1336295%2Fd183e316-935e-4060-a4dc-9c87027eaad4.png</url>
      <title>Forem: Gabriel Kalu</title>
      <link>https://forem.com/gabby1234</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/gabby1234"/>
    <language>en</language>
    <item>
      <title>Exploring JSX: The Gateway to React’s Powerful UI Construction</title>
      <dc:creator>Gabriel Kalu</dc:creator>
      <pubDate>Fri, 08 Mar 2024 18:51:52 +0000</pubDate>
      <link>https://forem.com/gabby1234/exploring-jsx-the-gateway-to-reacts-powerful-ui-construction-2cpc</link>
      <guid>https://forem.com/gabby1234/exploring-jsx-the-gateway-to-reacts-powerful-ui-construction-2cpc</guid>
      <description>&lt;p&gt;JSX, or JavaScript XML, is a syntax extension for JavaScript that is commonly used with React to describe the UI structure of an application. It allows developers to write HTML-like code in their JavaScript files, which is then transformed into React elements. Here's a deeper look into JSX and some advanced concepts associated with it:&lt;/p&gt;

&lt;h3&gt;
  
  
  JSX Syntax and Transpilation
&lt;/h3&gt;

&lt;p&gt;JSX looks similar to HTML but it's actually closer to JavaScript. When a React application is built, JSX expressions are transpiled into JavaScript function calls. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, world!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This JSX tag syntax is transformed into a &lt;code&gt;React.createElement()&lt;/code&gt; call:&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;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, world!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Embedding Expressions in JSX
&lt;/h3&gt;

&lt;p&gt;JSX is an expression too, which means you can embed JavaScript expressions in JSX by wrapping them in curly braces &lt;code&gt;{}&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Copilot&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;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  JSX Children and Composition
&lt;/h3&gt;

&lt;p&gt;You can compose complex UIs from simple pieces by nesting JSX tags within each other, similar to HTML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;header&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;My App&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;header&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;This is the content of my app.&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;main&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Advanced Concepts
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Virtual DOM and Reconciliation
&lt;/h4&gt;

&lt;p&gt;JSX elements become objects representing the virtual DOM. React's reconciliation algorithm efficiently updates the DOM by comparing changes in the virtual DOM with the actual DOM.&lt;/p&gt;

&lt;h4&gt;
  
  
  Fragments
&lt;/h4&gt;

&lt;p&gt;React Fragments allow you to group a list of children without adding extra nodes to the DOM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ChildA&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ChildB&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ChildC&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Portals
&lt;/h4&gt;

&lt;p&gt;Portals provide a way to render children into a DOM node that exists outside the DOM hierarchy of the parent component.&lt;/p&gt;

&lt;h4&gt;
  
  
  Higher-Order Components (HOC)
&lt;/h4&gt;

&lt;p&gt;HOCs are functions that take a component and return a new component, allowing you to reuse component logic.&lt;/p&gt;

&lt;h4&gt;
  
  
  Render Props
&lt;/h4&gt;

&lt;p&gt;Render props are a technique for sharing code between React components using a prop whose value is a function.&lt;/p&gt;

&lt;h4&gt;
  
  
  Context API
&lt;/h4&gt;

&lt;p&gt;The Context API allows you to share state across the entire app without passing props down manually at every level.&lt;/p&gt;

&lt;h4&gt;
  
  
  Hooks
&lt;/h4&gt;

&lt;p&gt;React Hooks, introduced in React 16.8, let you use state and other React features in functional components. For example, &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useEffect&lt;/code&gt; are hooks that let you add state and side effects to functional components.&lt;/p&gt;

&lt;p&gt;These advanced JSX and React concepts enable developers to build powerful and efficient applications. They provide the tools needed to manage state, handle side effects, and optimize performance, all within the expressive and declarative syntax of JSX. For more in-depth information, you can explore resources like the React documentation or community articles.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Sync Vs Defer in JavaScript</title>
      <dc:creator>Gabriel Kalu</dc:creator>
      <pubDate>Thu, 07 Mar 2024 18:10:34 +0000</pubDate>
      <link>https://forem.com/gabby1234/sync-vs-defer-in-javascript-16n6</link>
      <guid>https://forem.com/gabby1234/sync-vs-defer-in-javascript-16n6</guid>
      <description>&lt;p&gt;Sync and defer are two attributes that can be used to modify the behavior of script tags in HTML. They affect how and when the browser downloads and executes the JavaScript code.&lt;/p&gt;

&lt;p&gt;By default, when the browser encounters a script tag, it stops parsing the HTML document and waits for the script to download and run. This can cause delays in rendering the page, especially if the script is large or slow. To avoid this, sync and defer can be used to make the script load asynchronously, meaning that the browser can continue parsing the HTML while the script is being downloaded in the background.&lt;/p&gt;

&lt;h2&gt;
  
  
  DIFFERENCES BETWEEN SYNC AND DEFER
&lt;/h2&gt;

&lt;p&gt;The difference between sync and defer is that sync executes the script as soon as it is downloaded, while defer executes the script only after the HTML document is fully parsed. This means that sync scripts can still block the rendering of the page, while defer scripts do not. Another difference is that sync scripts do not guarantee the order of execution, while defer scripts preserve the order of the script tags.&lt;/p&gt;

&lt;p&gt;Here are some examples of how sync and defer can be used in code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To load a script asynchronously and execute it as soon as possible, use sync:
&lt;/li&gt;
&lt;/ul&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;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt; &lt;span class="na"&gt;async&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;ul&gt;
&lt;li&gt;To load a script asynchronously and execute it after the HTML document is parsed, use defer:
&lt;/li&gt;
&lt;/ul&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;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt; &lt;span class="na"&gt;defer&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;ul&gt;
&lt;li&gt;To load multiple scripts asynchronously and execute them in the order they appear in the HTML document, use defer for all of them:
&lt;/li&gt;
&lt;/ul&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;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script1.js"&lt;/span&gt; &lt;span class="na"&gt;defer&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;"script2.js"&lt;/span&gt; &lt;span class="na"&gt;defer&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;"script3.js"&lt;/span&gt; &lt;span class="na"&gt;defer&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;ul&gt;
&lt;li&gt;To load multiple scripts asynchronously and execute them as soon as possible, regardless of the order, use sync for all of them:
&lt;/li&gt;
&lt;/ul&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;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script1.js"&lt;/span&gt; &lt;span class="na"&gt;async&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;"script2.js"&lt;/span&gt; &lt;span class="na"&gt;async&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;"script3.js"&lt;/span&gt; &lt;span class="na"&gt;async&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;ul&gt;
&lt;li&gt;To load a script synchronously and block the HTML parsing until it is done, use neither sync nor defer:
&lt;/li&gt;
&lt;/ul&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;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.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;h2&gt;
  
  
  CONCLUSION
&lt;/h2&gt;

&lt;p&gt;In conclusion, sync and defer are two attributes that can affect how and when the browser downloads and executes the JavaScript code in script tags. Sync makes the script load asynchronously and execute as soon as it is downloaded, while defer makes the script load asynchronously and execute after the HTML document is parsed. Sync can improve the page loading speed, but it can also block the rendering of the page and disrupt the order of execution. Defer can improve the page rendering speed and preserve the order of execution, but it can also delay the execution of the script until the end. Therefore, the choice between sync and defer depends on the purpose and priority of the script.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
