<?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: WebDevZTH</title>
    <description>The latest articles on DEV Community by WebDevZTH (@webzth).</description>
    <link>https://dev.to/webzth</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%2F612597%2Fe9340202-00bf-4214-aa5e-23917fc81d9d.png</url>
      <title>DEV Community: WebDevZTH</title>
      <link>https://dev.to/webzth</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/webzth"/>
    <language>en</language>
    <item>
      <title>Epic Todo ✅</title>
      <dc:creator>WebDevZTH</dc:creator>
      <pubDate>Wed, 07 Sep 2022 16:53:18 +0000</pubDate>
      <link>https://dev.to/webzth/epic-todo-2l3</link>
      <guid>https://dev.to/webzth/epic-todo-2l3</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Implement a full-stack todo application in different tech stacks using different tools and techniques&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Aim ✨
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;To make a fullstack todo application with different variations of backend api's (REST, Graph, RPC) and frontend libraries/frameworks (React, react-native, Nextjs, graphql-client) using different tools and techniques.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview 📚
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Build different versions of client using &lt;code&gt;react, react-native, nextjs&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Use different client-side tools &lt;code&gt;react-query, axios, redux, redux-saga, mobx, custom hooks, graphql-client, react-bootstrap, tailwind-css, chakra-ui&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Use different rendering strategies &lt;code&gt;CSR, SSR, ISR (all using nextjs)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Build different versions of server api using &lt;code&gt;REST (MVC architecture), Graph (graphql), RPC (tRPC/gRPC)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Use different server-side tools &lt;code&gt;joi, yup, zod, jwt, express-jwt, bcrypt, argon2d, morgan, express, busboy, formidable, multer, helmet, winston&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Use different databases &lt;code&gt;postgres (SQL), mongodb (noSQL)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Use different ORMs &lt;code&gt;prisma, mongoose, typegoose&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Use firebase tools &lt;code&gt;firebase-auth, firestore&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Implement basic CI/CD using &lt;code&gt;github-actions&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;**Setup horizontal scaling with &lt;code&gt;pm2, nodejs-built-ins (fork, process, worker)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;**Use message-queues &lt;code&gt;rabbit-mq, bullmq&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;**Use server-side caching &lt;code&gt;redis&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;**Use websockets with &lt;code&gt;socket.io&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;PS: All items marked with &lt;em&gt;(**)&lt;/em&gt; will be low priority&lt;/p&gt;
&lt;/blockquote&gt;



&lt;h2&gt;
  
  
  Procedure 👨‍🔬
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Different versions of frontend todo-client using different libraries mentioned above.&lt;/li&gt;
&lt;li&gt;Fetch data using different tools mentioned above.&lt;/li&gt;
&lt;li&gt;Experiment with different client-side techniques like lazy-loading, Suspense, code-splitting and component-injection.&lt;/li&gt;
&lt;li&gt;Experiment different techniques in server-side like refresh-token/access-token, email verification, logging, clusters, thread-workers, caching, sticky-sessions.&lt;/li&gt;
&lt;li&gt;Enable basic CI/CD for projects.&lt;/li&gt;
&lt;li&gt;All different variations of stack will be in different branches of this repository.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Outcome 🎯
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Learn these different tools and tech stacks.&lt;/li&gt;
&lt;li&gt;Experiment with a variety of 3&lt;sup&gt;rd&lt;/sup&gt; party services like firebase-auth and firestore, other ecosystem tools.&lt;/li&gt;
&lt;li&gt;To Become a better full-stack engineer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why a todo-app ⚛️
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Its a dynamic application which requires GET, POST, PUT/PATCH, DELETE operations in terms of database operations.&lt;/li&gt;
&lt;li&gt;We can build this app with many variations and the codebase size will be manageable by a single or small group of devs who want to learn and explore hands on.&lt;/li&gt;
&lt;li&gt;We can experiment and prototype rapidly since the application logic is simple.&lt;/li&gt;
&lt;li&gt;We can then increase the engineering complexity and not feel lost due to simple nature of application.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  **Attention ( &lt;em&gt;for developers&lt;/em&gt; ) 🛑
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;This repository code is based in the nodejs and javascript ecosystem, we will mainly work with javascript and add typescript functionality in a different branch.&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Visit the repository on Github &lt;a href="https://github.com/utsavo-afk/epic-todo"&gt;Epic-Todo&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;PART I 👉 Full-stack todo app built using react, express and mongodb (coming soon!)&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Let me know if you'll be following along with the progress down in the comments 🥳&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>My Express application folder structure and setup for fullstack projects</title>
      <dc:creator>WebDevZTH</dc:creator>
      <pubDate>Tue, 10 Aug 2021 05:28:25 +0000</pubDate>
      <link>https://dev.to/webzth/my-express-application-folder-structure-and-setup-for-fullstack-projects-2p6l</link>
      <guid>https://dev.to/webzth/my-express-application-folder-structure-and-setup-for-fullstack-projects-2p6l</guid>
      <description>&lt;p&gt;So far I've been using Nodejs and Express in the back-end for all my full stack projects. I saw a lot of repositories and developers code to get an understanding of what a good folder structure should look like.&lt;/p&gt;

&lt;p&gt;Why bother with folder structure?&lt;br&gt;
Its all about the structure, it makes code maintainable and we can easily pin-point bugs, when they arise in the code base. It makes it easy for contributors to help grow the code base efficiently.&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%2Ftgod1bq59gble6mvg6tx.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%2Ftgod1bq59gble6mvg6tx.png" alt="Folder Structure for Express MVC backend"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A quick breakdown of the folders and files.&lt;br&gt;
At the root of the project we have a &lt;code&gt;configuration&lt;/code&gt; folder that houses the &lt;code&gt;config.js&lt;/code&gt; file and we can access the &lt;code&gt;.env&lt;/code&gt; file by using &lt;code&gt;dotenv&lt;/code&gt; package, safely and securely without compromising security of sensitive data like the database url, hashing secret and other keys that are critical to the development of our application.&lt;/p&gt;

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

&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dotenv&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;config&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;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;development&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PORT&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;3001&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;mongoUri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MONGODB_URI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;jwtSecret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;JWT_SECRET&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;YOUR_SECRET_KEY&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;braintreeId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;BRAINTREE_MERCHANT_ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;braintreePublicKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;BRAINTREE_PUBLIC_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;braintreePrivateKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;BRAINTREE_PRIVATE_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;Next, we can come to the MVC architecture of the application. The Model-View-Controller is at the heart of the application, the views are handled in the client folder with React. &lt;br&gt;
Models are where we define our database Schema or the structure of the way we want to store specific data into our database, In this project I have used MongoDB for the databse, it is a collection of documents and each document is an instance of the model we define. &lt;br&gt;
Controllers are the way we interact with the database to create, read, update, delete data to and from the database. All of the logic of how our server processes incoming requests and responds to users requests is handled by the controllers.&lt;br&gt;
Finally, Routes folder houses all the endpoints that we expose to query data and send information to the server, it contains different controller logic as middleware to sanitise and ensure that requests to the server are processed in the correct order.&lt;/p&gt;

&lt;p&gt;What is Model-View-Controller?&lt;br&gt;
This is a design pattern that is commonly used for web-applications and is one of the most popular design patterns. The View part in a MERN (Mongo, Express, React and Node) application is handled in the front-end by React library. The express based backend which is running in Node is where we have the Controllers, Routes and Models.&lt;/p&gt;

&lt;p&gt;Try using this approach in your next project, please share other interesting design patterns for full-stack web development projects ^_^&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>mongodb</category>
      <category>node</category>
    </item>
    <item>
      <title>Creating a custom hook in React to control form input</title>
      <dc:creator>WebDevZTH</dc:creator>
      <pubDate>Tue, 10 Aug 2021 03:56:47 +0000</pubDate>
      <link>https://dev.to/webzth/creating-a-custom-hook-in-react-to-control-form-input-47g7</link>
      <guid>https://dev.to/webzth/creating-a-custom-hook-in-react-to-control-form-input-47g7</guid>
      <description>&lt;p&gt;There are numerous ways to make a form input controlled from not controlled. The internet is mostly just a collection of forms ^_^ and one solution to make interacting with form inputs is to use the following approach...&lt;/p&gt;

&lt;p&gt;Suppose we have a form with a single input field&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;'username'&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;'submit'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Send&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example we are sending the field 'username' to our backend or to some end-point on submitting this form. To do this we must have two things a 'onSubmit' event and a way to keep track of the data entered into the input field of the form, one approach is...&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;form&lt;/span&gt; &lt;span class="nx"&gt;onSubmit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleFormSubmit&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'username'&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;button&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'submit'&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Send&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&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="err"&gt;/&lt;/span&gt;&lt;span class="na"&gt;form&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;The above snippet is making use of the 'useState' hook to make this component stateful. We are then passing the value and onChange event handler to the input field to keep track and store the value enetered into 'username'&lt;/p&gt;

&lt;p&gt;This approach works fine and good but we will have to define multiple 'onChange' event handlers if our form gets more input fields and as the complexity grows the components code will start to look messy. &lt;/p&gt;

&lt;p&gt;One thing we can use here is custom hooks, that is we create a function that utilises the react-hooks and customise its behaviour to suit our needs. One approach to do this is like so...&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useField&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;type&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&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;onChange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&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;reset&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="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;

 &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;reset&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can import this custom hook into any component where we want to use input fields, like so...&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;useField&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;..file its being exported from&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we can use it in our react component, like so..&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="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;text&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt; &lt;span class="na"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleFormSubmit&lt;/span&gt;&lt;span class="si"&gt;}&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;input&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'username'&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;button&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'submit'&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Send&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&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;form&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;Now one way to implement the &lt;code&gt;handleFormSubmit&lt;/code&gt; is like so...&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;handleFormSubmit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
 &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;userObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;username&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="c1"&gt;// send data to backend&lt;/span&gt;
 &lt;span class="nx"&gt;reset&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;We can call the reset method after successfully sending form-data to the backend and the input field is reset to an empty string.&lt;/p&gt;

&lt;p&gt;Using this approach we make the code much cleaner and dont need to use multiple useState hooks within our components which clutters the code.&lt;/p&gt;

&lt;p&gt;Try this in your next form in React! ^_^&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How I got comfortable with Javascript as a newbie</title>
      <dc:creator>WebDevZTH</dc:creator>
      <pubDate>Sun, 18 Apr 2021 08:49:16 +0000</pubDate>
      <link>https://dev.to/webzth/how-i-got-comfortable-with-javascript-as-a-newbie-1pmj</link>
      <guid>https://dev.to/webzth/how-i-got-comfortable-with-javascript-as-a-newbie-1pmj</guid>
      <description>&lt;h2&gt;
  
  
  Which programming language to pick?
&lt;/h2&gt;

&lt;p&gt;So you decide to get into web development and wonder which language you want to learn to code in, let me help you out.. The answer is straight forward, pick Javascript. &lt;br&gt;
&lt;strong&gt;NB&lt;/strong&gt;: &lt;em&gt;There are 2 kinds of programmers, the ones that type in JavaScript and the ones who type in Javascript. Pick one!&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Javascript, why not &lt;em&gt;xyz&lt;/em&gt; language?
&lt;/h2&gt;

&lt;p&gt;So it's a well know fact that the modern web is filled with multiple technologies, Javascript happens to be on in every single nook and cranny of the world wide web, so speak the language of the land you want to be a part of, you can always learn other languages later on. &lt;br&gt;
&lt;br&gt;&lt;br&gt;
Learning programming is not a linear progression, you won't get far following a step-wise learning approach, personally it doesn't work for me.&lt;br&gt;
If you want to build a chat application,you don't learn the &lt;em&gt;C&lt;/em&gt; programming language, then &lt;em&gt;python&lt;/em&gt;, then &lt;em&gt;Data Structures and Algorithms&lt;/em&gt;... you build a chat application, find out how to build one, what technologies are used and then get to work on that, linear progression in programming is a myth and doing 1000 different programming tutorials, ticking things off one by one in an imaginary check list of &lt;em&gt;'programming topics'&lt;/em&gt; you made isn't going to work. &lt;br&gt;
&lt;br&gt;&lt;br&gt;
Having said that, Javascript is a must for any aspiring web developer and it is amazing how you can learn one language and pick up the &lt;em&gt;fullstack&lt;/em&gt; as you get more experience!&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Javascript can be challenging but trust me the quirks of the language are awesome and the community of developers are so amazing, there's always help available to those that seek it. &lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to learn Javascript?
&lt;/h2&gt;

&lt;p&gt;Personally, the best resource for me to learn Javascript was &lt;a href="https://www.udemy.com/course/javascript-bible/?couponCode=D0067E0DDA850BF91BA2"&gt;this&lt;/a&gt; course by &lt;a href="https://stashchuk.com/"&gt;Bogdan Stashchuk&lt;/a&gt; and get a good understanding of most of the core features like &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ES5 syntax&lt;/li&gt;
&lt;li&gt;ES6 syntax&lt;/li&gt;
&lt;li&gt;Callback functions&lt;/li&gt;
&lt;li&gt;Asynchronous programming&lt;/li&gt;
&lt;li&gt;Javascript engine and how it functions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
For months I struggled with a slew of tutorials, code alongs and what-not until I saw this course and trust me, the name &lt;em&gt;Javascript Bible&lt;/em&gt; is no understatement.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;strong&gt;I am in no way affiliated or sponsored by Bogdan or Udemy, I just know this course is awesome and it helped me go from 0-100 in 4 months. I am confident of my Javascript skills and am always learning more, but my understanding of the internals of the language is all thanks to Bogdan's course!&lt;/strong&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  My learning path in the last 5-months
&lt;/h2&gt;

&lt;p&gt;So I wanted to share my learning path for web development with whoever comes across this article and is interested or wants some clarity on where to start..&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Have a project in mind! don't just learn code to be a coder, that's vague.&lt;/li&gt;
&lt;li&gt;Look at what tools and technologies are being used to create such applications.&lt;/li&gt;
&lt;li&gt;Do a code along an create that exact thing, it's okay if you don't understand, when you're confused, you're mind is learning!&lt;/li&gt;
&lt;li&gt;Now that you know the moving parts involved to build that application, get to work and start learning those skills. &lt;/li&gt;
&lt;li&gt;I wanted to build a website where I host my own tutorials and courses, even though I am a beginner but I want to put out free content for people to access. &lt;/li&gt;
&lt;li&gt;I looked at tutorials and code alongs of other experienced programmers and quickly understood that I wanted to learn node.js, react, HTML, CSS, Javascript. &lt;/li&gt;
&lt;li&gt;Okay, then I got to work. I'm still learning, I'm on the react bit now! Then I'll get to node.js :D&lt;/li&gt;
&lt;li&gt;Be realistic and give yourself time to learn and absorb, &lt;em&gt;&lt;strong&gt;you won't be a web developer in 4 months or 6 months&lt;/strong&gt;&lt;/em&gt;, give your self time, everyone has a different learning approach find yours and be patient. &lt;/li&gt;
&lt;/ol&gt;



&lt;h3&gt;
  
  
  Where I learned from:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.udemy.com/course/javascript-bible/?couponCode=D0067E0DDA850BF91BA2"&gt;Javascript&lt;/a&gt; by Bogdan Stashchuk, complete all of it and practice everyday.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Learn"&gt;HTML, CSS, Javascript&lt;/a&gt;, this is &lt;a href="https://developer.mozilla.org/en-US/"&gt;Mozilla's&lt;/a&gt; free-for-all &lt;em&gt;Web development&lt;/em&gt; bootcamp, complete this and you're on your way. Trust me, this is the best resource to start and get a good understanding of the old and modern web landscape.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://fullstackopen.com/en/"&gt;FullstackOpen 2021&lt;/a&gt;, once you are done with the previous parts and have built a couple of web pages, do this free-for-all fullstack modern web development course, it's organised by the &lt;a href="https://www.helsinki.fi/en"&gt;University of Helsinki&lt;/a&gt; and the content is a contribution of experienced and awesome developers, namely &lt;a href="https://github.com/mluukkai"&gt;Matti Luukkainen&lt;/a&gt; who is a professor at the University. &lt;/li&gt;
&lt;li&gt;Documentation! Always read the docs, as you do the first two parts of my suggested material, it will become easier to read the docs. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Have fun, keep coding and be patient! Good things come to those who wait&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>codenewbie</category>
      <category>100daysofcode</category>
      <category>firstyearincode</category>
    </item>
  </channel>
</rss>
