<?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: J0shcodes</title>
    <description>The latest articles on DEV Community by J0shcodes (@j0shcodes).</description>
    <link>https://dev.to/j0shcodes</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%2F746532%2F41c7d31a-a682-42d5-b982-08e3be0ebbb2.jpg</url>
      <title>DEV Community: J0shcodes</title>
      <link>https://dev.to/j0shcodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/j0shcodes"/>
    <language>en</language>
    <item>
      <title>Enhancing User Experience with Performance Optimization in Frontend Web Development</title>
      <dc:creator>J0shcodes</dc:creator>
      <pubDate>Sun, 03 Dec 2023 19:45:21 +0000</pubDate>
      <link>https://dev.to/j0shcodes/enhancing-user-experience-with-performance-optimization-in-frontend-web-development-2moo</link>
      <guid>https://dev.to/j0shcodes/enhancing-user-experience-with-performance-optimization-in-frontend-web-development-2moo</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;User expectations for responsive and quick-loading websites are higher than ever in today's digital environment. One of the most important aspects of providing a flawless user experience is performance optimization. In order to meet user expectations and raise overall happiness, this article will explore technological solutions and best practices for frontend speed optimization.&lt;/p&gt;

&lt;h2&gt;
  
  
  Importance of Performance Optimization
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Impact on user experience&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Performance optimization has a profound impact on the user experience in several crucial ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Page load speed:&lt;/strong&gt; Users expect websites to load quickly. Therefore, performance optimization guarantees quicker loading times, which lowers user annoyance and raises satisfaction levels overall.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User Engagement and Retention:&lt;/strong&gt; Improved performance results in a more fluid surfing experience, enabling users to explore more content and decreasing the likelihood of them abandoning the site owing to delayed loading or unresponsive pages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conversion rates and sales:&lt;/strong&gt; Faster websites typically have greater conversion rates because users are more likely to complete purchases or other actions on a site that responds quickly and smoothly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User Satisfaction:&lt;/strong&gt; A website that loads quickly enhances consumers' perceptions of the brand or service, which in turn builds customer happiness and trust.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;SEO and other Ranking Factors&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Page speed is a ranking factor for search engines such as Google. Better-performing websites are more likely to rank higher in search results, increasing visibility and garnering more organic traffic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Technical Strategies for Performance Optimization
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Minification and compression&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Minification
&lt;/h3&gt;

&lt;p&gt;Minification is the process of removing unnecessary characters from the source code file in order to reduce its size and thus improve loading speed without affecting its functionalities. This is especially true for HTML, CSS, and JavaScript files. The purpose is to reduce file size by removing whitespace characters, comments, and other items that aren't necessary for the code to run.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Original JavaScript code:&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;function&lt;/span&gt; &lt;span class="nf"&gt;calculateArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Calculate the area of a rectangle&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;height&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;ol&gt;
&lt;li&gt;The &lt;code&gt;calculateArea&lt;/code&gt; function is defined, which takes two parameters: &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Inside the function, there's a single line of code that multiplies the &lt;code&gt;width&lt;/code&gt; by the &lt;code&gt;height&lt;/code&gt; to compute the area of a rectangle.&lt;/li&gt;
&lt;li&gt;The comment &lt;code&gt;// Calculate the area of a rectangle&lt;/code&gt; provides a descriptive note for the purpose of the function.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Minified JavaScript code:&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;function&lt;/span&gt; &lt;span class="nf"&gt;calculateArea&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;calculateArea&lt;/code&gt; function remains the same, but the variable names width and height have been minified to &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; respectively.&lt;/li&gt;
&lt;li&gt;Whitespace characters, such as spaces and line breaks, are removed.&lt;/li&gt;
&lt;li&gt;The comment has been eliminated during the minification process.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;CSS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Original CSS code:&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="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Arial'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#f4f4f4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&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;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;h1&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="m"&gt;#333&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;28px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&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="m"&gt;#666&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.6&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;Minified CSS code:&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="nt"&gt;body&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;'Arial'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;#f4f4f4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;0&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;20px&lt;/span&gt;&lt;span class="p"&gt;;}&lt;/span&gt;&lt;span class="nt"&gt;h1&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="m"&gt;#333&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;28px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nl"&gt;margin-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;}&lt;/span&gt;&lt;span class="nt"&gt;p&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="m"&gt;#666&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;1.6&lt;/span&gt;&lt;span class="p"&gt;;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the minified version of the CSS code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Whitespace characters such as spaces, line breaks, and indentation have been removed.&lt;/li&gt;
&lt;li&gt;Comments have also been eliminated to reduce the file size.&lt;/li&gt;
&lt;li&gt;Shortened property names, where possible, are used without affecting the styling.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;HTML&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Original HTML:&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&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&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;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Minified HTML Example&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;header&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Welcome&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;nav&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;About&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Services&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Contact&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/header&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;main&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;This is an example of minified HTML code.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/main&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;footer&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;span class="ni"&gt;&amp;amp;copy;&lt;/span&gt; 2023 Minified HTML Example&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/footer&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;Minified HTML:&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&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;title&amp;gt;&lt;/span&gt;Minified HTML Example&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;&amp;lt;header&amp;gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Welcome&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&amp;lt;nav&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;About&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Services&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Contact&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/nav&amp;gt;&amp;lt;/header&amp;gt;&amp;lt;main&amp;gt;&amp;lt;p&amp;gt;&lt;/span&gt;This is an example of minified HTML code.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&amp;lt;/main&amp;gt;&amp;lt;footer&amp;gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;span class="ni"&gt;&amp;amp;copy;&lt;/span&gt; 2023 Minified HTML Example&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&amp;lt;/footer&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the minified HTML version:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Whitespace, indentation, and line breaks have been removed to reduce the overall file size.&lt;/li&gt;
&lt;li&gt;The structure and elements of the HTML document remain unchanged, but the formatting is condensed for optimization purposes.&lt;/li&gt;
&lt;li&gt;Minification in both CSS and HTML involves the removal of unnecessary characters and formatting to create more compact files for faster loading times in web browsers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are various tools available for performing CSS, JS, and HTML minification. Examples of those tools are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://csscompressor.net/"&gt;csscompressor.net&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.toptal.com/developers/cssminifier"&gt;cssminifier.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jscompress.com/"&gt;jscompress.com&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.toptal.com/developers/javascript-minifier"&gt;javascript-minifier.com&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Although minification greatly decreases the size of the code, it does not change its logic, allowing browsers to parse and download it more quickly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Compression
&lt;/h3&gt;

&lt;p&gt;Compression is the process of lowering file size by encoding data more efficiently for transmission. Gzip and Brotli are popular compression methods in web development.&lt;/p&gt;

&lt;p&gt;1 Gzip: A common technique for reducing the size of text-based files, such as HTML, CSS, JavaScript, and XML, is compression with Gzip. The server compresses the file before transmitting it over the network in response to a browser request for a gzipped file. The browser decompresses the file upon receiving it so that it may be used. Significant file size reductions with Gzip compression might result in quicker downloads and better website performance.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Brotli: Brotli is a more recent compression algorithm created by Google. It often has higher compression ratios than Gzip, resulting in reduced file sizes. Brotli is particularly useful for text-based content and is supported by the majority of recent browsers.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Image and asset optimization
Image and asset optimization is critical for increasing website performance by reducing file sizes while maintaining visual quality. The following are a few methods and recommended practices for picture and asset optimization:&lt;/li&gt;
&lt;li&gt;Image compression: Use proper image format by choosing the appropriate image format (JPEG, PNG, WebP, SVG) based on the content. For instance, JPEGs are great for photographs, PNGs for images with transparency, and SVGs for simple graphics or logos. Also, you can reduce file sizes while preserving acceptable image quality by using image compression tools or services (e.g., Adobe Photoshop, TinyPNG, ImageOptim).&lt;/li&gt;
&lt;li&gt;Responsive Image: Use the &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images#how_do_you_create_responsive_images"&gt;srcset and sizes&lt;/a&gt; properties of HTML to give alternative image sources dependent on the screen size and resolution of the device. This guarantees that suitable image sizes are supplied to various devices, avoiding excessive downloads on smaller screens.&lt;/li&gt;
&lt;li&gt;Icon and font optimisation: Consider using icon fonts or SVGs instead of multiple image icons. They scale well and can be styled with CSS without sacrificing quality.&lt;/li&gt;
&lt;li&gt;Lazy loading: Implement lazy loading for images so that they load just when the user is about to see them, rather than all at once when the page first loads. This minimizes the initial load time and saves bandwidth by only loading images when they are required. To enable lazy loading for images in HTML, use the loading="lazy" attribute in the &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tag. This property instructs the browser to wait until the picture is close to entering the viewport before loading it.
Example:
&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;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"image.jpg"&lt;/span&gt; &lt;span class="na"&gt;loading=&lt;/span&gt;&lt;span class="s"&gt;"lazy"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Description of the image"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Async loading and code splitting&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Async loading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Async attribute for JavaScript:
To load JavaScript files asynchronously, use the &lt;code&gt;async&lt;/code&gt; attribute in the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag. This enables the browser to download the script without interfering with HTML processing or other resources.
Example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;example.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Defer attribute for JavaScript:
The &lt;code&gt;defer&lt;/code&gt; property, like the load attribute, loads JavaScript asynchronously but ensures that scripts are run in the order they appear in the HTML only after the HTML parsing is complete.
Example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;example.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;defer&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Code splitting
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Webpack or module bundlers: &lt;br&gt;
Use module bundlers that support code splitting, such as Webpack, Rollup, or Parcel. These tools enable you to divide your JavaScript code into smaller portions that are loaded on demand, lowering the size of the initial bundle.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dynamic imports:&lt;br&gt;
The &lt;code&gt;import()&lt;/code&gt; syntax in modern JavaScript allows for dynamic imports. This enables code separation by allowing you to import modules asynchronously during runtime.&lt;br&gt;
Example using dynamic import():&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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;button&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;myButton&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./moduleToLoad.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// Use the dynamically imported module&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Tools and Metrics for Performance Measurement
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Performance monitoring tools: Performance monitoring tools like &lt;a href="https://openreplay.com/"&gt;OpenReplay&lt;/a&gt;, &lt;a href="https://chromewebstore.google.com/detail/lighthouse/blipmdconlkpinefehnmjammfjpmpbjk?pli=1"&gt;lighthouse&lt;/a&gt;, &lt;a href="https://www.webpagetest.org/"&gt;WebPageTest&lt;/a&gt;, &lt;a href="https://pagespeed.web.dev/"&gt;Google page speed&lt;/a&gt; helps you to measure and analyze your website performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Key Performance Metrics: They are key performance metrics you should look out for in your webpage as well as how it impacts user experience. They are:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://web.dev/articles/fcp"&gt;First Contentful Paint (FCP)&lt;/a&gt;: FCP measures the time it takes for the browser to render the first piece of content (text, image, or DOM element) on the screen. FCP represents the first impression of the website's loading progress. A faster FCP tells to users that the page is actively loading, lowering perceived load times and providing feedback on how responsive the site is. A sluggish FCP might cause user dissatisfaction and increase bounce rates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://web.dev/articles/tti"&gt;Time To Interactive (TTI)&lt;/a&gt;: TTI measures the time it takes for a web page to become fully interactive and responsive to user input. TTI is necessary for usability. It signals when users may interact with the website successfully, such as clicking buttons or entering data into forms. A speedier TTI offers a more seamless user experience, whereas a delayed TTI may lead to consumers perceiving the site as unresponsive or difficult to use, resulting in lower user engagement and satisfaction.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://web.dev/articles/cls"&gt;Cumulative Layout Shift (CLS)&lt;/a&gt;: CLS measures the unexpected and abrupt layout shifts of visible elements on a web page during its loading phase. Visible stability is directly impacted by CLS. Unexpected element shifts can cause user input problems, annoyance, or inadvertent clicks when users interact with the page. A high CLS score might interfere with reading, particularly when using a mobile device, as it can lead to users losing their place or inadvertently tapping on the wrong element.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Optimizing these key performance metrics contributes to a positive user experience by providing faster loading times, quicker interaction opportunities, and a more visually stable interface, ultimately leading to increased user satisfaction and engagement. Websites that want to increase performance and user retention frequently give priority to enhancing these metrics in order to improve the user experience overall.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Finally, focusing on performance optimization in frontend development is critical for providing a fast, responsive, and engaging user experience. Developers can dramatically improve website speed and user happiness by applying the recommended tactics and utilizing performance measurement tools.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>css</category>
      <category>html</category>
    </item>
    <item>
      <title>Web 2 vs Web 3: Highlighting their Differences</title>
      <dc:creator>J0shcodes</dc:creator>
      <pubDate>Wed, 02 Mar 2022 03:42:38 +0000</pubDate>
      <link>https://dev.to/j0shcodes/web-2-vs-web-3-highlighting-their-differences-4hoa</link>
      <guid>https://dev.to/j0shcodes/web-2-vs-web-3-highlighting-their-differences-4hoa</guid>
      <description>&lt;p&gt;Hopefully as at the time you will be reading this article, this won't be the first time you will be hearing the word "Web 2" or "Web 3". Probably you have stumbled on this article out of curiosity for what &lt;br&gt;
those two words mean, well you have come to the right place.&lt;/p&gt;

&lt;p&gt;In this article, I will be tabling the differences between Web 2 and Web 3, but before that, I will be defining and introducing what Web 2 and Web 3 is for us to get a quick understanding of what the two terms are. So sit tight because you are in for a smooth ride.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Web 2
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--beokU3EH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3qzljktz0xw7txz70cdg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--beokU3EH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3qzljktz0xw7txz70cdg.png" alt="Image of web 2" width="300" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The term was coined by &lt;strong&gt;Darcy DiNucci&lt;/strong&gt; in 1999 and later published by &lt;strong&gt;Tim O'Reilly&lt;/strong&gt; and &lt;strong&gt;Dale Dougherty&lt;/strong&gt; at the first &lt;strong&gt;O'Reilly Media Web 2.0 Conference&lt;/strong&gt; in late 2004.&lt;/p&gt;

&lt;p&gt;Web 2 is simply the version of the 21st-century internet we all know and use today, including social media sites. An internet dominated by data-hungry firms who provide services in exchange for your data. &lt;/p&gt;

&lt;p&gt;Web 2 relies on content interactivity, social engagement, and information exchange, rather than static content consumption. Take Facebook as an example, a tiny fraction of the overall content has been created by Facebook. Users are now allowed to create their content and interact with other users on the platform.  &lt;/p&gt;

&lt;p&gt;One of the goals of Web 2 is to unite people around the data that was interested in. Let's take a look at Web 3.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Web 3
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bf7UFvj_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cxyxcw03kdx9mhrjv8br.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bf7UFvj_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cxyxcw03kdx9mhrjv8br.jpg" alt="Image of web 3" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Web 3 is simply a decentralized ecosystem or application that is based and runs on the blockchain.&lt;/p&gt;

&lt;p&gt;Web3 applications either run on blockchains, decentralized networks of many peer-to-peer nodes (servers), or a combination of the two that forms a crypto economic protocol.&lt;/p&gt;

&lt;h2&gt;
  
  
  Difference between Web 2 and Web 3
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QGO9-UAL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fhr304z964wmi7mm2ti4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QGO9-UAL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fhr304z964wmi7mm2ti4.jpg" alt="Image of web 2 &amp;amp; web 3" width="320" height="158"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Having done justice to the definitions of the two terms, let us dive into the differences between the two terms. Here we will see what makes Web 2 tick and what has got people going crazy about Web 3.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;WEB 2.0&lt;/th&gt;
&lt;th&gt;WEB 3.0&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Widely Read Write&lt;/td&gt;
&lt;td&gt;Portable and Personal&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Community Focus&lt;/td&gt;
&lt;td&gt;Individual Focus&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Servers for gig-economy apps could go down and affect worker income&lt;/td&gt;
&lt;td&gt;Web3 servers can't go down – they use Ethereum, a decentralized network of 1000s of computers as their backend&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Web Applications&lt;/td&gt;
&lt;td&gt;Smart Applications&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Interactive Advertising&lt;/td&gt;
&lt;td&gt;Behavioral Advertising&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Payment service may decide to not allow payments for certain types of work&lt;/td&gt;
&lt;td&gt;Web3 payment apps require no personal data and can't prevent payments&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sharing Content&lt;/td&gt;
&lt;td&gt;Consolidating Content&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Participation in the network is controlled by the central authority.&lt;/td&gt;
&lt;td&gt;Anyone can participate in the network; there are no “gatekeepers.” Ideally, the cost of participation is very low.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Big things have started to be done using Web 3, yet the world hasn’t scratched the surface yet. Are you interested in diving into the world of Web 3 and taking full advantage of a promising future, then visit the sites to know more and also get free training on Web 3:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blockgames.gg/"&gt;Blockgames&lt;/a&gt;   &lt;a href="https://nestcoin.com/"&gt;Nestcoin&lt;/a&gt;  &lt;a href="https://zuri.team/"&gt;Zuri team&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Will the world see the complete emergence and usurp of Web 2 by Web 3? Well that is yet to be known. Till then, let's stay safe, stay alive and keep our fingers crossed. Happy Reading😉   &lt;/p&gt;

</description>
      <category>web2</category>
      <category>web3</category>
      <category>blockchain</category>
      <category>dapps</category>
    </item>
    <item>
      <title>React Form Validation With Formik and Yup</title>
      <dc:creator>J0shcodes</dc:creator>
      <pubDate>Wed, 10 Nov 2021 08:14:50 +0000</pubDate>
      <link>https://dev.to/j0shcodes/react-form-validation-with-formik-and-yup-39if</link>
      <guid>https://dev.to/j0shcodes/react-form-validation-with-formik-and-yup-39if</guid>
      <description>&lt;p&gt;Last time out, I showed how we can build a React form using the form library called Formik. In this article, I will be showing you how to validate the form we created using Yup.&lt;/p&gt;

&lt;p&gt;Below is how the form and code look like at the end of the first issue of this article:&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%2Ftp9eo8lbk9ag5p3xdzyn.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%2Ftp9eo8lbk9ag5p3xdzyn.png" alt="React form built with formik"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const UserForm = () =&amp;gt; {
    return (
      &amp;lt;Formik
        initialValues={{
          firstname: ''
          lastname: ''
          email: ''
          country: ''
          state: ''
          zip: '' 
        }}
        onSubmit={() =&amp;gt; {
         console.log('form submitted')
        }}
      &amp;gt;
        { ({
          values,
          errors,
          touched,
          handleChange,
          handleBlur,
          handleSubmit
        }) =&amp;gt; (
        &amp;lt;div className="container"&amp;gt;

          &amp;lt;div className="col-md-12 mt-5"&amp;gt;
            &amp;lt;form onSubmit={handleSubmit}&amp;gt;
              &amp;lt;h4 className="mb-3"&amp;gt;Personal information&amp;lt;/h4&amp;gt;

              &amp;lt;div className="row"&amp;gt;
                &amp;lt;div className="col-md-6 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="firstname"&amp;gt;First name&amp;lt;/label&amp;gt;
                  &amp;lt;input 
                    type="text" 
                    className="form-control" 
                    id="firstname" 
                    name="firstname" 
                    value={values.firstname}
                  /&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-6 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="lastname"&amp;gt;Last name&amp;lt;/label&amp;gt;
                  &amp;lt;input 
                    type="text" 
                    className="form-control" 
                    id="lastname" 
                    name="lastname" 
                    value={values.lastname}
                  /&amp;gt;
                &amp;lt;/div&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;div className="mb-3"&amp;gt;
                &amp;lt;label htmlFor="email"&amp;gt;Email&amp;lt;/label&amp;gt;
                &amp;lt;input 
                  type="email" 
                  className="form-control" 
                  id="email" 
                  name="email" 
                  placeholder="you@example.com" 
                  value={values.email}
                /&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;div className="row"&amp;gt;
                &amp;lt;div className="col-md-5 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="country"&amp;gt;Country&amp;lt;/label&amp;gt;
                  &amp;lt;select 
                    className="custom-select d-block w-100" 
                    id="country" 
                    name="country" 
                    value={values.country}
                  &amp;gt;
                    &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
                    &amp;lt;option value="NIG"&amp;gt;Nigeria&amp;lt;/option&amp;gt;
                    &amp;lt;option value="GH"&amp;gt;Ghana&amp;lt;/option&amp;gt;
                    &amp;lt;option value="SA"&amp;gt;South Africa&amp;lt;/option&amp;gt;
                  &amp;lt;/select&amp;gt;        
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-4 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="state"&amp;gt;State&amp;lt;/label&amp;gt;
                  &amp;lt;select 
                    className="custom-select d-block w-100" 
                    id="state" 
                    name="state" 
                    value={values.state}
                  &amp;gt;
                    &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
                    &amp;lt;option value="lagos"&amp;gt;Lagos&amp;lt;/option&amp;gt;
                    &amp;lt;option value="east legion"&amp;gt;East Legion&amp;lt;/option&amp;gt;
                    &amp;lt;option value="cape town"&amp;gt;Cape Town&amp;lt;/option&amp;gt;
                  &amp;lt;/select&amp;gt;             
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-3 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="zip"&amp;gt;Zip&amp;lt;/label&amp;gt;
                  &amp;lt;input 
                    type="text" 
                    className="form-control" 
                    id="zip" 
                    name="zip" 
                    value={values.zip}
                  /&amp;gt;
                &amp;lt;/div&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;hr className="mb-4"/&amp;gt;
              &amp;lt;button className="btn btn-primary btn-lg btn-block" type="submit"&amp;gt;
            Submit
              &amp;lt;/button&amp;gt;
           &amp;lt;/form&amp;gt;
         &amp;lt;/div&amp;gt;

       &amp;lt;/div&amp;gt;
        ) }
      &amp;lt;/Formik&amp;gt;
    )
}


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

&lt;/div&gt;

&lt;p&gt;If you are just coming across this article and you haven't read the first issue where I created the form using Formik, then you should probably go check out &lt;a href="https://dev.to/j0shcodes/building-react-forms-painlessly-with-formik-nhj"&gt;Building React Forms Painlessly With Formik&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now there are different ways we can validate our forms, we can validate the form manually with Formik or we can validate it using Yup. In this article, I will only be showing you the Yup way, because I have resolved to make this particular article less lengthy than the last one.&lt;/p&gt;

&lt;p&gt;To begin we will have to install Yup by running &lt;code&gt;npm install yup&lt;/code&gt; in our command line. Make sure the current directory you are in when running this command is your React project folder.     &lt;/p&gt;

&lt;p&gt;In the previous article, I named the file that houses the form as &lt;code&gt;userForm.js&lt;/code&gt;. It is in this file we will be importing Yup as follows:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import * as Yup from 'yup'


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

&lt;/div&gt;

&lt;p&gt;Importing Yup into our file gives us access to a property called &lt;code&gt;validationSchema&lt;/code&gt; that we can add to the &lt;code&gt;Formik&lt;/code&gt; component&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

validationSchema = {Yup.object({
  firstname: Yup
    .string()
    .required('Sorry, this is required')
    .max(5, 'Sorry, name is too long'),
  lastname: Yup
    .string()
    .required('Sorry, this is required'),
  email: Yup
    .string()
    .required('Sorry, this is required')
    .email('Invalid email format')
})}


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

&lt;/div&gt;

&lt;p&gt;We see from the code above that we can target specific properties that we want to validate in the &lt;code&gt;validationSchema&lt;/code&gt;, which in turn gives us access to several methods that we can use for validation. The strings provided in some of the methods are the error messages that will be displayed if a particular input field fails a validation.&lt;/p&gt;

&lt;p&gt;Now we will need to add some logic to show the error message on our &lt;code&gt;form&lt;/code&gt; component when an input field fails a validation. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;div className="container"&amp;gt;

  &amp;lt;div className="col-md-12 mt-5"&amp;gt;
    &amp;lt;form onSubmit={handleSubmit}&amp;gt;
      &amp;lt;h4 className="mb-3"&amp;gt;Personal information&amp;lt;/h4&amp;gt;

      &amp;lt;div className="row"&amp;gt;
        &amp;lt;div className="col-md-6 mb-3"&amp;gt;
          &amp;lt;label htmlFor="firstname"&amp;gt;First name&amp;lt;/label&amp;gt;
          &amp;lt;input 
            type="text" 
            className="form-control" 
            id="firstname" 
            name="firstname" 
            value={values.firstname}
            onChange={handleChange}
            onBlur={handleBlur}
          /&amp;gt;
          {errors.firstname &amp;amp;&amp;amp; touched.firstname ?
            &amp;lt;span style={{color: 'red'}}&amp;gt;
              {errors.firstname}
            &amp;lt;/span&amp;gt;
          : null}      
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="col-md-6 mb-3"&amp;gt;
          &amp;lt;label htmlFor="lastname"&amp;gt;Last name&amp;lt;/label&amp;gt;
          &amp;lt;input 
            type="text" 
            className="form-control" 
            id="lastname" 
            name="lastname" 
            value={values.lastname}
            onChange={handleChange}
            onBlur={handleBlur}
          /&amp;gt;
          {errors.lastname &amp;amp;&amp;amp; touched.lastname ?
            &amp;lt;span style={{color: 'red'}}&amp;gt;
              {errors.lastname}
            &amp;lt;/span&amp;gt;
          : null} 
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div className="mb-3"&amp;gt;
        &amp;lt;label htmlFor="email"&amp;gt;Email&amp;lt;/label&amp;gt;
        &amp;lt;input 
          type="email" 
          className="form-control" 
          id="email" 
          name="email" 
          placeholder="you@example.com" 
          value={values.email}
          onChange={handleChange}
          onBlur={handleBlur}
        /&amp;gt;
        {errors.email &amp;amp;&amp;amp; touched.email ?
          &amp;lt;span style={{color: 'red'}}&amp;gt;
            {errors.firstname}
          &amp;lt;/span&amp;gt;
        : null} 
      &amp;lt;/div&amp;gt;

      &amp;lt;div className="row"&amp;gt;
        &amp;lt;div className="col-md-5 mb-3"&amp;gt;
          &amp;lt;label htmlFor="country"&amp;gt;Country&amp;lt;/label&amp;gt;
          &amp;lt;select 
            className="custom-select d-block w-100" 
            id="country" 
            name="country" 
            value={values.country}
            onChange={handleChange}
          &amp;gt;
            &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
            &amp;lt;option value="NIG"&amp;gt;Nigeria&amp;lt;/option&amp;gt;
            &amp;lt;option value="GH"&amp;gt;Ghana&amp;lt;/option&amp;gt;
            &amp;lt;option value="SA"&amp;gt;South Africa&amp;lt;/option&amp;gt;
          &amp;lt;/select&amp;gt;        
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="col-md-4 mb-3"&amp;gt;
          &amp;lt;label htmlFor="state"&amp;gt;State&amp;lt;/label&amp;gt;
          &amp;lt;select 
            className="custom-select d-block w-100" 
            id="state" 
            name="state" 
            value={values.state}
            onChange={handleChange}
          &amp;gt;
            &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
            &amp;lt;option value="lagos"&amp;gt;Lagos&amp;lt;/option&amp;gt;
            &amp;lt;option value="east legion"&amp;gt;East Legion&amp;lt;/option&amp;gt;
            &amp;lt;option value="cape town"&amp;gt;Cape Town&amp;lt;/option&amp;gt;
          &amp;lt;/select&amp;gt;             
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="col-md-3 mb-3"&amp;gt;
          &amp;lt;label htmlFor="zip"&amp;gt;Zip&amp;lt;/label&amp;gt;
          &amp;lt;input 
            type="text" 
            className="form-control" 
            id="zip" 
            name="zip" 
            value={values.zip}
            onChange={handleChange}
          /&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;hr className="mb-4"/&amp;gt;
      &amp;lt;button className="btn btn-primary btn-lg btn-block" type="submit"&amp;gt;
        Submit
      &amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  &amp;lt;/div&amp;gt;

&amp;lt;/div&amp;gt;


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

&lt;/div&gt;

&lt;p&gt;We get access to the error messages passed into the methods in the &lt;code&gt;validationSchema&lt;/code&gt; from the errors object. To display the error message, &lt;code&gt;errors.firstname&lt;/code&gt; checks if there was an error when validating the firstname input field and &lt;code&gt;touched.firstname&lt;/code&gt; checks if the firstname input field was accessed or clicked on by the user. If both conditions passes, we display an error below the input field, else, no error is displayed.&lt;/p&gt;

&lt;p&gt;The final code when we pass the &lt;code&gt;validationSchema&lt;/code&gt; as a property to the &lt;code&gt;Formik&lt;/code&gt; looks like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const UserForm = () =&amp;gt; {
    return (
      &amp;lt;Formik
        initialValues={{
          firstname: ''
          lastname: ''
          email: ''
          country: ''
          state: ''
          zip: '' 
        }}
        validationSchema = {Yup.object({
          firstname: Yup
            .string()
            .required('Sorry, this is required')
            .max(5, 'Sorry, name is too long'),
          lastname: Yup
            .string()
            .required('Sorry, this is required'),
          email: Yup
            .string()
            .required('Sorry, this is required')
            .email('Invalid email format')
        })}
        onSubmit={() =&amp;gt; {
         console.log('form submitted')
        }}
      &amp;gt;
        { ({
          values,
          errors,
          touched,
          handleChange,
          handleBlur,
          handleSubmit
        }) =&amp;gt; (
        &amp;lt;div className="container"&amp;gt;

          &amp;lt;div className="col-md-12 mt-5"&amp;gt;
            &amp;lt;form onSubmit={handleSubmit}&amp;gt;
              &amp;lt;h4 className="mb-3"&amp;gt;Personal information&amp;lt;/h4&amp;gt;

              &amp;lt;div className="row"&amp;gt;
                &amp;lt;div className="col-md-6 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="firstname"&amp;gt;First name&amp;lt;/label&amp;gt;
                  &amp;lt;input 
                    type="text" 
                    className="form-control" 
                    id="firstname" 
                    name="firstname" 
                    value={values.firstname}
                    onChange={handleChange}
                    onBlur={handleBlur}
                  /&amp;gt;
                  {errors.firstname &amp;amp;&amp;amp; touched.firstname ?
                    &amp;lt;span style={{color: 'red'}}&amp;gt;
                      {errors.firstname}
                    &amp;lt;/span&amp;gt;
                  : null} 
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-6 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="lastname"&amp;gt;Last name&amp;lt;/label&amp;gt;
                  &amp;lt;input 
                    type="text" 
                    className="form-control" 
                    id="lastname" 
                    name="lastname" 
                    value={values.lastname}
                    onChange={handleChange}
                    onBlur={handleBlur}
                  /&amp;gt;
                  {errors.lastname &amp;amp;&amp;amp; touched.lastname ?
                    &amp;lt;span style={{color: 'red'}}&amp;gt;
                      {errors.lastname}
                    &amp;lt;/span&amp;gt;
                  : null} 
                &amp;lt;/div&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;div className="mb-3"&amp;gt;
                &amp;lt;label htmlFor="email"&amp;gt;Email&amp;lt;/label&amp;gt;
                &amp;lt;input 
                  type="email" 
                  className="form-control" 
                  id="email" 
                  name="email" 
                  placeholder="you@example.com" 
                  value={values.email}
                  onChange={handleChange}
                  onBlur={handleBlur}
                /&amp;gt;
                {errors.email &amp;amp;&amp;amp; touched.email ?
                  &amp;lt;span style={{color: 'red'}}&amp;gt;
                    {errors.email}
                  &amp;lt;/span&amp;gt;
                : null} 
              &amp;lt;/div&amp;gt;

              &amp;lt;div className="row"&amp;gt;
                &amp;lt;div className="col-md-5 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="country"&amp;gt;Country&amp;lt;/label&amp;gt;
                  &amp;lt;select 
                    className="custom-select d-block w-100" 
                    id="country" 
                    name="country" 
                    value={values.country}
                    onChange={handleChange}
                  &amp;gt;
                    &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
                    &amp;lt;option value="NIG"&amp;gt;Nigeria&amp;lt;/option&amp;gt;
                    &amp;lt;option value="GH"&amp;gt;Ghana&amp;lt;/option&amp;gt;
                    &amp;lt;option value="SA"&amp;gt;South Africa&amp;lt;/option&amp;gt;
                  &amp;lt;/select&amp;gt;        
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-4 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="state"&amp;gt;State&amp;lt;/label&amp;gt;
                  &amp;lt;select 
                    className="custom-select d-block w-100" 
                    id="state" 
                    name="state" 
                    value={values.state}
                    onChange={handleChange}
                  &amp;gt;
                    &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
                    &amp;lt;option value="lagos"&amp;gt;Lagos&amp;lt;/option&amp;gt;
                    &amp;lt;option value="east legion"&amp;gt;East Legion&amp;lt;/option&amp;gt;
                    &amp;lt;option value="cape town"&amp;gt;Cape Town&amp;lt;/option&amp;gt;
                  &amp;lt;/select&amp;gt;             
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-3 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="zip"&amp;gt;Zip&amp;lt;/label&amp;gt;
                  &amp;lt;input 
                    type="text" 
                    className="form-control" 
                    id="zip" 
                    name="zip" 
                    value={values.zip}
                    onChange={handleChange}
                  /&amp;gt;
                &amp;lt;/div&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;hr className="mb-4"/&amp;gt;
              &amp;lt;button className="btn btn-primary btn-lg btn-block" type="submit"&amp;gt;
               Submit
              &amp;lt;/button&amp;gt;
            &amp;lt;/form&amp;gt;
          &amp;lt;/div&amp;gt;

        &amp;lt;/div&amp;gt;
        ) }
      &amp;lt;/Formik&amp;gt;
    )
}


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

&lt;/div&gt;

&lt;p&gt;That is it for this article. As you can see, with Formik and Yup we are able to avoid unnecessary boilerplate code. Formik handles the validation by default. So as you are entering values and clicking submit, it is running the validation and won't submit until all form values can pass.&lt;/p&gt;

&lt;p&gt;Fomik makes it easy to access and update form values. Use &lt;code&gt;handleChange&lt;/code&gt; to handle update and the &lt;code&gt;values&lt;/code&gt; object holds all the current values. Same with the &lt;code&gt;errors&lt;/code&gt; object we use to display the error messages for individual fields.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/b796tzgZ3oQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Above, is a demo on how our form should look and work.&lt;/p&gt;

&lt;p&gt;Hope you find this article as useful as the first. Thanks and have a nice read. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>form</category>
      <category>formik</category>
    </item>
    <item>
      <title>Building React Forms Painlessly With Formik</title>
      <dc:creator>J0shcodes</dc:creator>
      <pubDate>Mon, 08 Nov 2021 11:46:10 +0000</pubDate>
      <link>https://dev.to/j0shcodes/building-react-forms-painlessly-with-formik-nhj</link>
      <guid>https://dev.to/j0shcodes/building-react-forms-painlessly-with-formik-nhj</guid>
      <description>&lt;p&gt;Forms are really important for us as web developers, because on every application you do in real life, you are probably going to need to do forms.&lt;/p&gt;

&lt;p&gt;Building forms in React can be tiring and can get messy. If you have a small form with few data inputs you can build it without using a form library. The same can't be said when building forms with larger number of data inputs and validation rules.&lt;/p&gt;

&lt;p&gt;In this article, I am going to demonstrate building forms with Formik. I am also going to go into the features Formik provides. This is the screenshot of what we will be building: &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%2Ff7c3l3u446ni19x4u5ui.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%2Ff7c3l3u446ni19x4u5ui.png" alt="Image of a web form made with formik"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Formik Forms
&lt;/h1&gt;

&lt;p&gt;We will start by creating a React application on our local environment. To do this, we open the command line and go to a document folder using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd documents
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that we create our React application and install &lt;code&gt;bootstrap&lt;/code&gt; to add a little bit of styles to our form by using the classes provided by &lt;code&gt;bootstrap&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Run the following commands in the command line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app formik-forms
cd formik-forms
npm install react-bootstrap bootstrap
npm install formik
yarn start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The commands above should get us to the point where we have created a new React project, installed pretty much the needed dependencies, and are running the app locally.&lt;/p&gt;

&lt;p&gt;After the React project has been created on your computer, open it with your preferred code editor and create a new file called &lt;code&gt;userForm.js&lt;/code&gt;. Add the following code to the new file created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react'
import {Formik} from 'formik'
import 'bootstrap/dist/css/bootstrap.min.css'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will be using functions, functional components, and the following form template I have created already with bootstrap. Since you have installed and imported bootstrap into your React project, you shouldn't have any issues with this. &lt;/p&gt;

&lt;p&gt;So you can copy and paste the template below into your own &lt;code&gt;userForm.js&lt;/code&gt; file or better still create your own using bootstrap&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div className="container"&amp;gt;

  &amp;lt;div className="col-md-12 mt-5"&amp;gt;
    &amp;lt;form&amp;gt;
      &amp;lt;h4 className="mb-3"&amp;gt;Personal information&amp;lt;/h4&amp;gt;

      &amp;lt;div className="row"&amp;gt;
        &amp;lt;div className="col-md-6 mb-3"&amp;gt;
          &amp;lt;label htmlFor="firstname"&amp;gt;First name&amp;lt;/label&amp;gt;
          &amp;lt;input type="text" className="form-control" id="firstname" name="firstname"/&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="col-md-6 mb-3"&amp;gt;
          &amp;lt;label htmlFor="lastname"&amp;gt;Last name&amp;lt;/label&amp;gt;
          &amp;lt;input type="text" className="form-control" id="lastname" name="lastname"/&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div className="mb-3"&amp;gt;
        &amp;lt;label htmlFor="email"&amp;gt;Email&amp;lt;/label&amp;gt;
        &amp;lt;input type="email" className="form-control" id="email" name="email" placeholder="you@example.com"/&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div className="row"&amp;gt;
        &amp;lt;div className="col-md-5 mb-3"&amp;gt;
          &amp;lt;label htmlFor="country"&amp;gt;Country&amp;lt;/label&amp;gt;
          &amp;lt;select className="custom-select d-block w-100" id="country" name="country"&amp;gt;
            &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
            &amp;lt;option value="NIG"&amp;gt;Nigeria&amp;lt;/option&amp;gt;
            &amp;lt;option value="GH"&amp;gt;Ghana&amp;lt;/option&amp;gt;
            &amp;lt;option value="SA"&amp;gt;South Africa&amp;lt;/option&amp;gt;
          &amp;lt;/select&amp;gt;        
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="col-md-4 mb-3"&amp;gt;
          &amp;lt;label htmlFor="state"&amp;gt;State&amp;lt;/label&amp;gt;
          &amp;lt;select className="custom-select d-block w-100" id="state" name="state"&amp;gt;
            &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
            &amp;lt;option value="lagos"&amp;gt;Lagos&amp;lt;/option&amp;gt;
            &amp;lt;option value="east legion"&amp;gt;East Legion&amp;lt;/option&amp;gt;
            &amp;lt;option value="cape town"&amp;gt;Cape Town&amp;lt;/option&amp;gt;
          &amp;lt;/select&amp;gt;             
        &amp;lt;/div&amp;gt;
        &amp;lt;div className="col-md-3 mb-3"&amp;gt;
          &amp;lt;label htmlFor="zip"&amp;gt;Zip&amp;lt;/label&amp;gt;
          &amp;lt;input type="text" className="form-control" id="zip" name="zip"/&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;hr className="mb-4"/&amp;gt;
      &amp;lt;button className="btn btn-primary btn-lg btn-block" type="submit"&amp;gt;
            Submit
      &amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
   &amp;lt;/div&amp;gt;

&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Still in our userForm.js file, I will be wrapping the form components in the &lt;code&gt;Formik&lt;/code&gt; component we imported earlier, but before that, we will have to declare our &lt;code&gt;Formik&lt;/code&gt; component and provide a function that gives us props with a lot of method that we will use inside our form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const UserForm = () =&amp;gt; {
    return (
      &amp;lt;Formik&amp;gt;
        { ({
          values,
          errors,
          touched,
          handleChange,
          handleBlur,
          handleSubmit
        }) =&amp;gt; (
        ) }
      &amp;lt;/Formik&amp;gt;
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, I have de-structured the various methods we need from the props, this will make it easier for us to use as properties in our form. For example, we can now do &lt;code&gt;values&lt;/code&gt;, instead of &lt;code&gt;props.values&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;The next thing to do is to return some JSX or in this case our &lt;code&gt;form&lt;/code&gt; components in the &lt;code&gt;Formik&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const UserForm = () =&amp;gt; {
    return (
      &amp;lt;Formik&amp;gt;
        { ({
          values,
          errors,
          touched,
          handleChange,
          handleBlur,
          handleSubmit
        }) =&amp;gt; (
        &amp;lt;div className="container"&amp;gt;

          &amp;lt;div className="col-md-12 mt-5"&amp;gt;
            &amp;lt;form&amp;gt;
              &amp;lt;h4 className="mb-3"&amp;gt;Personal information&amp;lt;/h4&amp;gt;

              &amp;lt;div className="row"&amp;gt;
                &amp;lt;div className="col-md-6 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="firstname"&amp;gt;First name&amp;lt;/label&amp;gt;
                  &amp;lt;input type="text" className="form-control" id="firstname" name="firstname"/&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-6 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="lastname"&amp;gt;Last name&amp;lt;/label&amp;gt;
                  &amp;lt;input type="text" className="form-control" id="lastname" name="lastname"/&amp;gt;
                &amp;lt;/div&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;div className="mb-3"&amp;gt;
                &amp;lt;label htmlFor="email"&amp;gt;Email&amp;lt;/label&amp;gt;
                &amp;lt;input type="email" className="form-control" id="email" name="email" placeholder="you@example.com"/&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;div className="row"&amp;gt;
                &amp;lt;div className="col-md-5 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="country"&amp;gt;Country&amp;lt;/label&amp;gt;
                  &amp;lt;select className="custom-select d-block w-100" id="country" name="country"&amp;gt;
                    &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
                    &amp;lt;option value="NIG"&amp;gt;Nigeria&amp;lt;/option&amp;gt;
                    &amp;lt;option value="GH"&amp;gt;Ghana&amp;lt;/option&amp;gt;
                    &amp;lt;option value="SA"&amp;gt;South Africa&amp;lt;/option&amp;gt;
                  &amp;lt;/select&amp;gt;        
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-4 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="state"&amp;gt;State&amp;lt;/label&amp;gt;
                  &amp;lt;select className="custom-select d-block w-100" id="state" name="state"&amp;gt;
                    &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
                    &amp;lt;option value="lagos"&amp;gt;Lagos&amp;lt;/option&amp;gt;
                    &amp;lt;option value="east legion"&amp;gt;East Legion&amp;lt;/option&amp;gt;
                    &amp;lt;option value="cape town"&amp;gt;Cape Town&amp;lt;/option&amp;gt;
                  &amp;lt;/select&amp;gt;             
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-3 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="zip"&amp;gt;Zip&amp;lt;/label&amp;gt;
                  &amp;lt;input type="text" className="form-control" id="zip" name="zip"/&amp;gt;
                &amp;lt;/div&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;hr className="mb-4"/&amp;gt;
              &amp;lt;button className="btn btn-primary btn-lg btn-block" type="submit"&amp;gt;
            Submit
             &amp;lt;/button&amp;gt;
           &amp;lt;/form&amp;gt;
         &amp;lt;/div&amp;gt;

       &amp;lt;/div&amp;gt;
        ) }
      &amp;lt;/Formik&amp;gt;
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the &lt;code&gt;Formik&lt;/code&gt; component requires properties. One a property that helps formik to know what we are going to be using on the form i.e the values that &lt;code&gt;Formik&lt;/code&gt; component will be controlling and another property that controls the submission of the form when a submit button is clicked.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const UserForm = () =&amp;gt; {
    return (
      &amp;lt;Formik
        initialValues={{
          firstname: ''
          lastname: ''
          email: ''
          country: ''
          state: ''
          zip: '' 
        }}
        onSubmit={() =&amp;gt; {
         console.log('form submitted')
        }}
      &amp;gt;
        { ({
          values,
          errors,
          touched,
          handleChange,
          handleBlur,
          handleSubmit
        }) =&amp;gt; (
        &amp;lt;div className="container"&amp;gt;

          &amp;lt;div className="col-md-12 mt-5"&amp;gt;
            &amp;lt;form&amp;gt;
              &amp;lt;h4 className="mb-3"&amp;gt;Personal information&amp;lt;/h4&amp;gt;

              &amp;lt;div className="row"&amp;gt;
                &amp;lt;div className="col-md-6 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="firstname"&amp;gt;First name&amp;lt;/label&amp;gt;
                  &amp;lt;input type="text" className="form-control" id="firstname" name="firstname"/&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-6 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="lastname"&amp;gt;Last name&amp;lt;/label&amp;gt;
                  &amp;lt;input type="text" className="form-control" id="lastname" name="lastname"/&amp;gt;
                &amp;lt;/div&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;div className="mb-3"&amp;gt;
                &amp;lt;label htmlFor="email"&amp;gt;Email&amp;lt;/label&amp;gt;
                &amp;lt;input type="email" className="form-control" id="email" name="email" placeholder="you@example.com"/&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;div className="row"&amp;gt;
                &amp;lt;div className="col-md-5 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="country"&amp;gt;Country&amp;lt;/label&amp;gt;
                  &amp;lt;select className="custom-select d-block w-100" id="country" name="country"&amp;gt;
                    &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
                    &amp;lt;option value="NIG"&amp;gt;Nigeria&amp;lt;/option&amp;gt;
                    &amp;lt;option value="GH"&amp;gt;Ghana&amp;lt;/option&amp;gt;
                    &amp;lt;option value="SA"&amp;gt;South Africa&amp;lt;/option&amp;gt;
                  &amp;lt;/select&amp;gt;        
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-4 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="state"&amp;gt;State&amp;lt;/label&amp;gt;
                  &amp;lt;select className="custom-select d-block w-100" id="state" name="state"&amp;gt;
                    &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
                    &amp;lt;option value="lagos"&amp;gt;Lagos&amp;lt;/option&amp;gt;
                    &amp;lt;option value="east legion"&amp;gt;East Legion&amp;lt;/option&amp;gt;
                    &amp;lt;option value="cape town"&amp;gt;Cape Town&amp;lt;/option&amp;gt;
                  &amp;lt;/select&amp;gt;             
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-3 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="zip"&amp;gt;Zip&amp;lt;/label&amp;gt;
                  &amp;lt;input type="text" className="form-control" id="zip" name="zip"/&amp;gt;
                &amp;lt;/div&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;hr className="mb-4"/&amp;gt;
              &amp;lt;button className="btn btn-primary btn-lg btn-block" type="submit"&amp;gt;
            Submit
             &amp;lt;/button&amp;gt;
           &amp;lt;/form&amp;gt;
         &amp;lt;/div&amp;gt;

       &amp;lt;/div&amp;gt;
        ) }
      &amp;lt;/Formik&amp;gt;
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;form&lt;/code&gt; component, you will notice all input components has an &lt;code&gt;id&lt;/code&gt;. It is these &lt;code&gt;id&lt;/code&gt; values that we use as the keys in the &lt;code&gt;initialValues&lt;/code&gt; object. For the form submission, I will just be displaying a string in the browser's console &lt;code&gt;console.log('form submitted')&lt;/code&gt; since we are not working with a server or database in this article.&lt;/p&gt;

&lt;p&gt;We will need to link the &lt;code&gt;initialValues&lt;/code&gt; property to the actual input we will be getting from our form by adding a &lt;code&gt;value&lt;/code&gt; property to the &lt;code&gt;input&lt;/code&gt; components and accessing users input from the &lt;code&gt;values&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const UserForm = () =&amp;gt; {
    return (
      &amp;lt;Formik
        initialValues={{
          firstname: ''
          lastname: ''
          email: ''
          country: ''
          state: ''
          zip: '' 
        }}
        onSubmit={() =&amp;gt; {
         console.log('form submitted')
        }}
      &amp;gt;
        { ({
          values,
          errors,
          touched,
          handleChange,
          handleBlur,
          handleSubmit
        }) =&amp;gt; (
        &amp;lt;div className="container"&amp;gt;

          &amp;lt;div className="col-md-12 mt-5"&amp;gt;
            &amp;lt;form&amp;gt;
              &amp;lt;h4 className="mb-3"&amp;gt;Personal information&amp;lt;/h4&amp;gt;

              &amp;lt;div className="row"&amp;gt;
                &amp;lt;div className="col-md-6 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="firstname"&amp;gt;First name&amp;lt;/label&amp;gt;
                  &amp;lt;input 
                    type="text" 
                    className="form-control" 
                    id="firstname" 
                    name="firstname" 
                    value={values.firstname}
                  /&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-6 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="lastname"&amp;gt;Last name&amp;lt;/label&amp;gt;
                  &amp;lt;input 
                    type="text" 
                    className="form-control" 
                    id="lastname" 
                    name="lastname" 
                    value={values.lastname}
                  /&amp;gt;
                &amp;lt;/div&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;div className="mb-3"&amp;gt;
                &amp;lt;label htmlFor="email"&amp;gt;Email&amp;lt;/label&amp;gt;
                &amp;lt;input 
                  type="email" 
                  className="form-control" 
                  id="email" 
                  name="email" 
                  placeholder="you@example.com" 
                  value={values.email}
                /&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;div className="row"&amp;gt;
                &amp;lt;div className="col-md-5 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="country"&amp;gt;Country&amp;lt;/label&amp;gt;
                  &amp;lt;select 
                    className="custom-select d-block w-100" 
                    id="country" 
                    name="country" 
                    value={values.country}
                  &amp;gt;
                    &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
                    &amp;lt;option value="NIG"&amp;gt;Nigeria&amp;lt;/option&amp;gt;
                    &amp;lt;option value="GH"&amp;gt;Ghana&amp;lt;/option&amp;gt;
                    &amp;lt;option value="SA"&amp;gt;South Africa&amp;lt;/option&amp;gt;
                  &amp;lt;/select&amp;gt;        
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-4 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="state"&amp;gt;State&amp;lt;/label&amp;gt;
                  &amp;lt;select 
                    className="custom-select d-block w-100" 
                    id="state" 
                    name="state" 
                    value={values.state}
                  &amp;gt;
                    &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
                    &amp;lt;option value="lagos"&amp;gt;Lagos&amp;lt;/option&amp;gt;
                    &amp;lt;option value="east legion"&amp;gt;East Legion&amp;lt;/option&amp;gt;
                    &amp;lt;option value="cape town"&amp;gt;Cape Town&amp;lt;/option&amp;gt;
                  &amp;lt;/select&amp;gt;             
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-3 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="zip"&amp;gt;Zip&amp;lt;/label&amp;gt;
                  &amp;lt;input 
                    type="text" 
                    className="form-control" 
                    id="zip" 
                    name="zip" 
                    value={values.zip}
                  /&amp;gt;
                &amp;lt;/div&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;hr className="mb-4"/&amp;gt;
              &amp;lt;button className="btn btn-primary btn-lg btn-block" type="submit"&amp;gt;
            Submit
             &amp;lt;/button&amp;gt;
           &amp;lt;/form&amp;gt;
         &amp;lt;/div&amp;gt;

       &amp;lt;/div&amp;gt;
        ) }
      &amp;lt;/Formik&amp;gt;
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally we will need to add an &lt;code&gt;onSubmit&lt;/code&gt; property to our &lt;code&gt;form&lt;/code&gt; component and pass in the &lt;code&gt;handleSubmit&lt;/code&gt; method from the &lt;code&gt;Formik&lt;/code&gt; component, and also add an &lt;code&gt;onChange&lt;/code&gt; property to the input components and pass in the &lt;code&gt;handleChange&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const UserForm = () =&amp;gt; {
    return (
      &amp;lt;Formik
        initialValues={{
          firstname: ''
          lastname: ''
          email: ''
          country: ''
          state: ''
          zip: '' 
        }}
        onSubmit={() =&amp;gt; {
         console.log('form submitted')
        }}
      &amp;gt;
        { ({
          values,
          errors,
          touched,
          handleChange,
          handleBlur,
          handleSubmit
        }) =&amp;gt; (
        &amp;lt;div className="container"&amp;gt;

          &amp;lt;div className="col-md-12 mt-5"&amp;gt;
            &amp;lt;form onSubmit={handleSubmit}&amp;gt;
              &amp;lt;h4 className="mb-3"&amp;gt;Personal information&amp;lt;/h4&amp;gt;

              &amp;lt;div className="row"&amp;gt;
                &amp;lt;div className="col-md-6 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="firstname"&amp;gt;First name&amp;lt;/label&amp;gt;
                  &amp;lt;input 
                    type="text" 
                    className="form-control" 
                    id="firstname" 
                    name="firstname" 
                    value={values.firstname}
                  /&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-6 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="lastname"&amp;gt;Last name&amp;lt;/label&amp;gt;
                  &amp;lt;input 
                    type="text" 
                    className="form-control" 
                    id="lastname" 
                    name="lastname" 
                    value={values.lastname}
                  /&amp;gt;
                &amp;lt;/div&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;div className="mb-3"&amp;gt;
                &amp;lt;label htmlFor="email"&amp;gt;Email&amp;lt;/label&amp;gt;
                &amp;lt;input 
                  type="email" 
                  className="form-control" 
                  id="email" 
                  name="email" 
                  placeholder="you@example.com" 
                  value={values.email}
                /&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;div className="row"&amp;gt;
                &amp;lt;div className="col-md-5 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="country"&amp;gt;Country&amp;lt;/label&amp;gt;
                  &amp;lt;select 
                    className="custom-select d-block w-100" 
                    id="country" 
                    name="country" 
                    value={values.country}
                  &amp;gt;
                    &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
                    &amp;lt;option value="NIG"&amp;gt;Nigeria&amp;lt;/option&amp;gt;
                    &amp;lt;option value="GH"&amp;gt;Ghana&amp;lt;/option&amp;gt;
                    &amp;lt;option value="SA"&amp;gt;South Africa&amp;lt;/option&amp;gt;
                  &amp;lt;/select&amp;gt;        
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-4 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="state"&amp;gt;State&amp;lt;/label&amp;gt;
                  &amp;lt;select 
                    className="custom-select d-block w-100" 
                    id="state" 
                    name="state" 
                    value={values.state}
                  &amp;gt;
                    &amp;lt;option value=""&amp;gt;Choose...&amp;lt;/option&amp;gt;
                    &amp;lt;option value="lagos"&amp;gt;Lagos&amp;lt;/option&amp;gt;
                    &amp;lt;option value="east legion"&amp;gt;East Legion&amp;lt;/option&amp;gt;
                    &amp;lt;option value="cape town"&amp;gt;Cape Town&amp;lt;/option&amp;gt;
                  &amp;lt;/select&amp;gt;             
                &amp;lt;/div&amp;gt;
                &amp;lt;div className="col-md-3 mb-3"&amp;gt;
                  &amp;lt;label htmlFor="zip"&amp;gt;Zip&amp;lt;/label&amp;gt;
                  &amp;lt;input 
                    type="text" 
                    className="form-control" 
                    id="zip" 
                    name="zip" 
                    value={values.zip}
                  /&amp;gt;
                &amp;lt;/div&amp;gt;
              &amp;lt;/div&amp;gt;

              &amp;lt;hr className="mb-4"/&amp;gt;
              &amp;lt;button className="btn btn-primary btn-lg btn-block" type="submit"&amp;gt;
            Submit
             &amp;lt;/button&amp;gt;
           &amp;lt;/form&amp;gt;
         &amp;lt;/div&amp;gt;

       &amp;lt;/div&amp;gt;
        ) }
      &amp;lt;/Formik&amp;gt;
    )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In my next article, which will be a sequel to this one, I will be expanding on the form we created here by doing some form validation with &lt;strong&gt;Yup&lt;/strong&gt; a library used for easy form validation.&lt;/p&gt;

&lt;p&gt;Well that does it for this article. I hope you do find article useful.&lt;/p&gt;

&lt;p&gt;Thanks and have a nice read.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>forms</category>
      <category>formik</category>
    </item>
  </channel>
</rss>
