<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Krushna Chandra Dash</title>
    <description>The latest articles on Forem by Krushna Chandra Dash (@krushnachandradash654).</description>
    <link>https://forem.com/krushnachandradash654</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%2F1057098%2F5ca29086-0f4f-4799-a119-5a1480002c62.jpeg</url>
      <title>Forem: Krushna Chandra Dash</title>
      <link>https://forem.com/krushnachandradash654</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/krushnachandradash654"/>
    <language>en</language>
    <item>
      <title>Run React App Localhost in Https in 2 steps</title>
      <dc:creator>Krushna Chandra Dash</dc:creator>
      <pubDate>Fri, 13 Oct 2023 08:57:35 +0000</pubDate>
      <link>https://forem.com/krushnachandradash654/run-react-app-localhost-in-https-in-2-steps-264d</link>
      <guid>https://forem.com/krushnachandradash654/run-react-app-localhost-in-https-in-2-steps-264d</guid>
      <description>&lt;p&gt;&lt;strong&gt;Question&lt;/strong&gt;-&amp;gt;&lt;br&gt;
How do I use the React development server to serve requests from https while working on localhost?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Ex -&amp;gt;&lt;a href="https://localhost:3000" rel="noopener noreferrer"&gt;https://localhost:3000&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of using &lt;code&gt;Https&lt;/code&gt;in localhost&lt;/strong&gt;&lt;/p&gt;

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

1. Access to 3rd party API's without CORS error.
2. Working with cookies made easy.
3. Accessing Google and Facebook API's without deploying the 
    application.


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

&lt;/div&gt;




&lt;h2&gt;
  
  
  For React App Created with &lt;strong&gt;&lt;em&gt;&lt;u&gt;Vite&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;




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

&lt;p&gt;1.Install &lt;a href="https://www.npmjs.com/package/vite-plugin-mkcert" rel="noopener noreferrer"&gt;vite-plugin-mkcert&lt;/a&gt; package.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step-2&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Change in &lt;code&gt;vite.config.js&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

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

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import mkcert from 'vite-plugin-mkcert'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react(),mkcert()],
  server:{
    port:3000,
    https: true
  }

})


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

&lt;/div&gt;

&lt;p&gt;and then start your application with &lt;code&gt;npm run dev&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  For React App Created with &lt;strong&gt;&lt;em&gt;&lt;u&gt;create-react-app&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;




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

&lt;p&gt;1.Install &lt;a href="https://www.npmjs.com/package/cross-env" rel="noopener noreferrer"&gt;cross-env&lt;/a&gt; package.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step-2&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Modify &lt;strong&gt;&lt;em&gt;start&lt;/em&gt;&lt;/strong&gt; script in package.json
and it should look like this&lt;/li&gt;
&lt;/ol&gt;

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

    "start": "cross-env HTTPS=true react-scripts start",



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

&lt;/div&gt;

&lt;p&gt;and Done .. Now Run your app using &lt;code&gt;npm start&lt;/code&gt;.&lt;/p&gt;







&lt;p&gt;if you get any package issue plese install all the package again using &lt;code&gt;npm install&lt;/code&gt; or &lt;code&gt;yarn install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If facing any issue in browser like this&lt;br&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%2F1henwqszqqw1qy8g9s92.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%2F1henwqszqqw1qy8g9s92.png" alt="Run React App Localhost in Https in 2 steps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;then click on &lt;code&gt;advance&lt;/code&gt;button and click on &lt;code&gt;continue to site&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fasf3aj7xt9zbtdb3ovry.jpg" 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%2Fasf3aj7xt9zbtdb3ovry.jpg" alt="Run React App Localhost in Https in 2 steps"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;.. Happy coding..&lt;/p&gt;

&lt;p&gt;if this article helps  please don't forget to Share with other..&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Learn git revert Step by Step (to revert commit in GitHub)</title>
      <dc:creator>Krushna Chandra Dash</dc:creator>
      <pubDate>Fri, 15 Sep 2023 07:32:08 +0000</pubDate>
      <link>https://forem.com/krushnachandradash654/learn-git-revert-to-revert-commit-in-github-1idj</link>
      <guid>https://forem.com/krushnachandradash654/learn-git-revert-to-revert-commit-in-github-1idj</guid>
      <description>&lt;p&gt;Let say, you have Committed some change and pushed the changes to your git repo.&lt;br&gt;
But now you want to revert/remove  the changes from your git repo as well as from your local machine, then &lt;strong&gt;git revert&lt;/strong&gt; can help you.&lt;/p&gt;

&lt;p&gt;Note-&amp;gt; This command won't remove the commit from commit history, it only revert the change from files.&lt;/p&gt;

&lt;p&gt;As per Google&lt;br&gt;
&lt;em&gt;The git revert command is a forward-moving undo operation that offers a safe method of undoing changes. Instead of deleting or orphaning commits in the commit history, a revert will create a new commit that inverses the changes specified&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;to read from git documentation &lt;a href="https://git-scm.com/docs/git-revert"&gt;https://git-scm.com/docs/git-revert&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Step-1&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We need commit id to revert the specific commit. So to get commit id enter below command in your code editor terminal or command prompt.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;this will show list of commit with commit id, author, Date and commit Name&lt;/p&gt;

&lt;p&gt;IMAGE 1-&amp;gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wilBeOHT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sxh5g07ij058h134tzcj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wilBeOHT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sxh5g07ij058h134tzcj.png" alt="git log" width="617" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;so the top one will show the latest commit. so copy the id from the log and close the process by pressing &lt;strong&gt;&lt;em&gt;semicolon + q&lt;/em&gt;&lt;/strong&gt; button.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Step-2&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now lets use &lt;strong&gt;&lt;em&gt;git revert&lt;/em&gt;&lt;/strong&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git revert &amp;lt;commit-id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;IMAGE 2 -&amp;gt; &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xYM874-2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qxy9iotbrvdgyfcfq16i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xYM874-2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qxy9iotbrvdgyfcfq16i.png" alt="git revert" width="733" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and press &lt;code&gt;Enter&lt;/code&gt;.&lt;br&gt;
after enter we will see screen like this :&lt;/p&gt;

&lt;p&gt;IMAGE 3 -&amp;gt; &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NBvTqLhp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c7sw1khbv9e89a939xm5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NBvTqLhp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c7sw1khbv9e89a939xm5.png" alt="git revert" width="800" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;you can see your &lt;em&gt;&lt;strong&gt;commit name&lt;/strong&gt;&lt;/em&gt; and &lt;em&gt;&lt;strong&gt;commit id&lt;/strong&gt;&lt;/em&gt; with &lt;em&gt;&lt;strong&gt;files that have changes&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Step-3&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;So now we have to exit vim and commit the changes.&lt;br&gt;
To do that press.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;Ctrl+C&lt;/code&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;after pressing &lt;code&gt;Ctrl+C&lt;/code&gt; it will ask to &lt;code&gt;Type: qa and press enter&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;IMAGE 4 -&amp;gt; &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lj2uaLhG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3nv1kyixwa0wpx8h70db.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lj2uaLhG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3nv1kyixwa0wpx8h70db.png" alt="git revert" width="800" height="401"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.Then type &lt;code&gt;qa&lt;/code&gt; and press &lt;code&gt;Enter&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And you will exit of vim ui. and screen will look like this.&lt;br&gt;
And you will see that you have created one commit and that is the reverted commit.&lt;/p&gt;

&lt;p&gt;IMAGE 5 -&amp;gt; &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pLALuBLK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0xsjvslb7d7pohdpeg15.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pLALuBLK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0xsjvslb7d7pohdpeg15.png" alt="git revert" width="800" height="225"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Step-4&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now we have to push the reverted commit by using git push.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;and Done.&lt;/p&gt;

&lt;p&gt;if you see the commit list you will see you have added one new commit starting with &lt;code&gt;Revert&lt;/code&gt; key.&lt;/p&gt;

&lt;p&gt;IMAGE 6 -&amp;gt; &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zJZ7zqhD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8s4t5q4sr2xmlcujmhs6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zJZ7zqhD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8s4t5q4sr2xmlcujmhs6.png" alt="commit List" width="800" height="109"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's all guys.. And All the best.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>git</category>
      <category>github</category>
    </item>
    <item>
      <title>Advance Add Tags input with REACT JS</title>
      <dc:creator>Krushna Chandra Dash</dc:creator>
      <pubDate>Sun, 13 Aug 2023 17:25:08 +0000</pubDate>
      <link>https://forem.com/krushnachandradash654/advance-add-tags-input-with-react-js-9gg</link>
      <guid>https://forem.com/krushnachandradash654/advance-add-tags-input-with-react-js-9gg</guid>
      <description>&lt;p&gt;Hi guys. In this article we will create a advance multiple tags input using React.JS and a bit of CSS.&lt;/p&gt;

&lt;p&gt;Where user can &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;&lt;em&gt;Add tag by entering comma(,) .&lt;/em&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;em&gt;Add tag by pressing "Enter" key.&lt;/em&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;em&gt;Edit last tag by entering "Back Space".&lt;/em&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;em&gt;On Blur add input text to Tag list.&lt;/em&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qmqMdzj3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njpq8vsaudej9d6qgold.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qmqMdzj3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njpq8vsaudej9d6qgold.JPG" alt="Advance Add Tags input with REACT JS" width="423" height="173"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;No time to ready then here is the &lt;code&gt;CodeSandbox&lt;/code&gt; link.&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;CodeSandbox&lt;/code&gt; &lt;a href="https://8xjvmz.csb.app/"&gt;DEMO&lt;/a&gt;&lt;br&gt;
&lt;code&gt;CodeSandbox&lt;/code&gt; &lt;a href="https://codesandbox.io/s/adavncetagsinput-8xjvmz"&gt;Code Example&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Step-1&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Create A react js project.&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 my_app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step-2&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Then lets create a component name of &lt;strong&gt;AdavnceTagsInput.js&lt;/strong&gt;.&lt;br&gt;
and the code with logic whick will look like below&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, { useState, useRef } from "react";
import "./AdavnceTagsInput.css";

export const AdavnceTagsInput = () =&amp;gt; {
  // to store input field data
  const [tagText, setTagText] = useState("");

  // to store tags data in array form
  const [tags, setTags] = useState([]);

  // to handle focus or blur state of input field
  const [isKeyReleased, setIsKeyReleased] = React.useState(false);
  const inputRef = useRef(null);

  const onChange = (e) =&amp;gt; {
    const { value } = e.target;
    setTagText(value);
  };

  return (
    &amp;lt;div className="CustomTagComp" &amp;gt;
      &amp;lt;div className="selected_tag"&amp;gt;
        {tags.map((tag, index) =&amp;gt; (
          &amp;lt;div key={index} style={{ display: "flex" }}&amp;gt;
            &amp;lt;span className="selected_tag_text"&amp;gt;{tag}&amp;lt;/span&amp;gt;
            &amp;lt;button  className="selected_tag_button" &amp;gt;
              &amp;amp;#10005;
            &amp;lt;/button&amp;gt;
          &amp;lt;/div&amp;gt;
        ))}
        &amp;lt;input
          value={tagText}
          placeholder="Enter Tag"
          className="tags_input"
        /&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step-3&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Then lets add &lt;em&gt;onKeyDown&lt;/em&gt; function, where we will check whether input field value is there . And on Enter or using comma(,) we will add value to tag list&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// handle key down
    const onKeyDown = (e) =&amp;gt; {
    const { key } = e;
    const trimmedInput = tagText.trim(); // remove extra space from both side

    // on entering "," add text to tag list
    if (key === "," &amp;amp;&amp;amp; trimmedInput.length &amp;amp;&amp;amp; !tags.includes(trimmedInput)) {
      e.preventDefault();
      setTags(
        (prevState) =&amp;gt;
          !prevState.includes(trimmedInput) &amp;amp;&amp;amp; [...prevState, trimmedInput]
      );
      setTagText("");
    }

    // on press enter add text to tag list
    if (
      key === "Enter" &amp;amp;&amp;amp;
      trimmedInput.length &amp;amp;&amp;amp;
      !tags.includes(trimmedInput)
    ) {
      e.preventDefault();
      setTags(
        (prevState) =&amp;gt;
          !prevState.includes(trimmedInput) &amp;amp;&amp;amp; [...prevState, trimmedInput]
      );
      setTagText("");
    }

    // on press back space user can exit last tag list
    if (
      key === "Backspace" &amp;amp;&amp;amp;
      !tagText.length &amp;amp;&amp;amp;
      tags.length &amp;amp;&amp;amp;
      isKeyReleased
    ) {
      const tagsCopy = [...tags];
      const poppedTag = tagsCopy.pop();
      e.preventDefault();
      setTags(tagsCopy);
      setTagText(poppedTag);
    }

    setIsKeyReleased(false);
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Then lets add &lt;em&gt;onKeyUp&lt;/em&gt; function, where we will make our isKeyReleased false ,means we move out of input field&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const onKeyUp = () =&amp;gt; {
    setIsKeyReleased(true);
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step-5&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Then lets add &lt;em&gt;removeTag&lt;/em&gt; function, when user click on remove button in tag, we will remove tag from tag list .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const removeTag = (index) =&amp;gt; {
    setTags((prevState) =&amp;gt; prevState.filter((tag, i) =&amp;gt; i !== index));
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step-6&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Then lets add &lt;em&gt;handleFocus&lt;/em&gt; function, So when user click on anywhere of input tag box, we will make input field focus .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const handleFocus = (e) =&amp;gt; {
    let input = inputRef.current;
    e.stopPropagation();
    if (tags &amp;amp;&amp;amp; tags.length &amp;gt; 0) {
      input.classList.remove("d-none");
    }
    input.focus();
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step-7&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Then lets add &lt;em&gt;handleBlur&lt;/em&gt; function, When user enter some text and move out of input field without adding value to tag list, then we will add the value to tag list automatically.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   const handleBlur = () =&amp;gt; {
    setIsKeyReleased(false);
    if (tagText) {
      let trimmedInput = tagText.replace(/,/g, "");
      if (trimmedInput.length &amp;amp;&amp;amp; !tags.includes(trimmedInput)) {
        setTags(
          (prevState) =&amp;gt;
            !prevState.includes(trimmedInput) &amp;amp;&amp;amp; [...prevState, trimmedInput]
        );
      }
      setTagText("");
    }
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Finally&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;So finally our &lt;code&gt;AdavnceTagsInput.js&lt;/code&gt; will look like this.&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, { useState, useRef } from "react";
import "./AdavnceTagsInput.css";

export const AdavnceTagsInput = () =&amp;gt; {
  // to store input field data
  const [tagText, setTagText] = useState("");
  // to store tags data in array form
  const [tags, setTags] = useState([]);
  // to handle focus or blur state of input field
  const [isKeyReleased, setIsKeyReleased] = React.useState(false);
  const inputRef = useRef(null);

  const onChange = (e) =&amp;gt; {
    const { value } = e.target;
    setTagText(value);
  };

  // handle key down
  const onKeyDown = (e) =&amp;gt; {
    const { key } = e;
    const trimmedInput = tagText.trim(); // remove extra space from both side

    // on entering "," add text to tag list
    if (key === "," &amp;amp;&amp;amp; trimmedInput.length &amp;amp;&amp;amp; !tags.includes(trimmedInput)) {
      e.preventDefault();
      setTags(
        (prevState) =&amp;gt;
          !prevState.includes(trimmedInput) &amp;amp;&amp;amp; [...prevState, trimmedInput]
      );
      setTagText("");
    }

    // on press enter add text to tag list
    if (
      key === "Enter" &amp;amp;&amp;amp;
      trimmedInput.length &amp;amp;&amp;amp;
      !tags.includes(trimmedInput)
    ) {
      e.preventDefault();
      setTags(
        (prevState) =&amp;gt;
          !prevState.includes(trimmedInput) &amp;amp;&amp;amp; [...prevState, trimmedInput]
      );
      setTagText("");
    }

    // on press back space user can exit last tag list
    if (
      key === "Backspace" &amp;amp;&amp;amp;
      !tagText.length &amp;amp;&amp;amp;
      tags.length &amp;amp;&amp;amp;
      isKeyReleased
    ) {
      const tagsCopy = [...tags];
      const poppedTag = tagsCopy.pop();
      e.preventDefault();
      setTags(tagsCopy);
      setTagText(poppedTag);
    }

    setIsKeyReleased(false);
  };

  // handle key up
  const onKeyUp = () =&amp;gt; {
    setIsKeyReleased(true);
  };

  // handle remove tag from tag list
  const removeTag = (index) =&amp;gt; {
    setTags((prevState) =&amp;gt; prevState.filter((tag, i) =&amp;gt; i !== index));
  };

  // handle focus
  const handleFocus = (e) =&amp;gt; {
    let input = inputRef.current;
    e.stopPropagation();
    if (tags &amp;amp;&amp;amp; tags.length &amp;gt; 0) {
      input.classList.remove("d-none");
    }
    input.focus();
  };

  // handle blur
  const handleBlur = () =&amp;gt; {
    setIsKeyReleased(false);
    if (tagText) {
      let trimmedInput = tagText.replace(/,/g, "");
      if (trimmedInput.length &amp;amp;&amp;amp; !tags.includes(trimmedInput)) {
        setTags(
          (prevState) =&amp;gt;
            !prevState.includes(trimmedInput) &amp;amp;&amp;amp; [...prevState, trimmedInput]
        );
      }
      setTagText("");
    }
  };

  return (
    &amp;lt;div className="CustomTagComp" onClick={handleFocus}&amp;gt;
      &amp;lt;div className="selected_tag"&amp;gt;
        {tags.map((tag, index) =&amp;gt; (
          &amp;lt;div key={index} style={{ display: "flex" }}&amp;gt;
            &amp;lt;span className="selected_tag_text"&amp;gt;{tag}&amp;lt;/span&amp;gt;
            &amp;lt;button
              onClick={() =&amp;gt; removeTag(index)}
              className="selected_tag_button"
            &amp;gt;
              &amp;amp;#10005;
            &amp;lt;/button&amp;gt;
          &amp;lt;/div&amp;gt;
        ))}
        &amp;lt;input
          ref={inputRef}
          value={tagText}
          placeholder="Enter Tag"
          onKeyDown={onKeyDown}
          onBlur={handleBlur}
          onKeyUp={onKeyUp}
          onChange={onChange}
          className="tags_input"
        /&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;And at end Add CSS&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;So finally our &lt;code&gt;AdavnceTagsInput.css&lt;/code&gt; will look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.selected_tag {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  cursor: text;
  border: 2px solid;
  padding: 4px;
  border-radius: 4px;
  gap: 4px;
}
.selected_tag_text {
  /* font-size: 11px; */
  color: rgb(0, 0, 0);
  padding: 4px;
  background-color: rgb(218, 216, 216);
  border-radius: 4px 0px 0px 4px;
  border: none;
  word-break: break-all;
  cursor: text;
}
.selected_tag_button {
  /* font-size: 9px; */
  border: none;
  background-color: rgb(218, 216, 216);
  padding: 4px;
  border-left: 1px solid #ffffff;
  border-radius: 0px 4px 4px 0px;
  color: rgb(0, 0, 0);
  margin-right: 5px;
  font-weight: bold;
  cursor: pointer;
}
.tags_input {
  box-sizing: border-box;
  width: 0;
  min-width: 30px;
  flex-grow: 1;
  border: 0;
  margin: 0;
  outline: 0;
}
.tag_input:focus-visible {
  outline: none;
}

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

&lt;/div&gt;



&lt;p&gt;And that's all we have successfully create a tags input using React and Bit of JavaScript.&lt;/p&gt;

&lt;p&gt;Found it helpful? Hit like and share with other&lt;/p&gt;

&lt;p&gt;Make sure you checkout my other articles&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Build a Memory Game using React.Js and JavaScript</title>
      <dc:creator>Krushna Chandra Dash</dc:creator>
      <pubDate>Sat, 22 Apr 2023 09:25:14 +0000</pubDate>
      <link>https://forem.com/krushnachandradash654/build-a-memory-game-using-reactjs-and-javascript-207m</link>
      <guid>https://forem.com/krushnachandradash654/build-a-memory-game-using-reactjs-and-javascript-207m</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;What is Memory Card Game&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Memory Game, also known as the Concentration card game or Matching Game, is a simple card game where you need to match pairs by turning over 2 cards at a time.&lt;/p&gt;

&lt;p&gt;In this Article we are going to create a game of grid size 3 x 4 .&lt;br&gt;
&lt;code&gt;CodeSandbox&lt;/code&gt; &lt;a href="https://qsogyj.csb.app/"&gt;DEMO&lt;/a&gt;&lt;br&gt;
&lt;code&gt;CodeSandbox&lt;/code&gt; &lt;a href="https://codesandbox.io/s/memory-card-game-javascript-qsogyj"&gt;Code Example&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Step-1&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Create A react js project.&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-next-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Step-2&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We need some data and image to show in the game.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create a **app.mock.js** file and store the above data.

const MOCK = [
  {
    id: 1,
    name: "Ace",
    pic: 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/ab/01_of_spades_A.svg/800px-01_of_spades_A.svg.png',
    isOpen: false
  },
  {
    id: 2,
    name: "Two",
    pic: 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/40/02_of_spades.svg/800px-02_of_spades.svg.png',
    isOpen: false
  },
  {
    id: 3,
    name: "Three",
    pic: 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/62/03_of_spades.svg/800px-03_of_spades.svg.png',
    isOpen: false
  },
  {
    id: 4,
    name: "Four",
    pic: 'https://upload.wikimedia.org/wikipedia/commons/7/7a/04_of_spades.svg',
    isOpen: false
  },
  {
    id: 5,
    name: "Five",
    pic: 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/16/05_of_spades.svg/800px-05_of_spades.svg.png',
    isOpen: false
  },
  {
    id: 6,
    name: "Six",
    pic: 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/6e/06_of_spades.svg/800px-06_of_spades.svg.png',
    isOpen: false
  },
  {
    id: 7,
    name: "Ace",
    pic: 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/ab/01_of_spades_A.svg/800px-01_of_spades_A.svg.png',
    isOpen: false
  },
  {
    id: 8,
    name: "Two",
    pic: 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/40/02_of_spades.svg/800px-02_of_spades.svg.png',
    isOpen: false
  },
  {
    id: 9,
    name: "Three",
    pic: 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/62/03_of_spades.svg/800px-03_of_spades.svg.png',
    isOpen: false
  },
  {
    id: 10,
    name: "Four",
    pic: 'https://upload.wikimedia.org/wikipedia/commons/thumb/7/7a/04_of_spades.svg/800px-04_of_spades.svg.png',
    isOpen: false
  },
  {
    id: 11,
    name: "Five",
    pic: 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/16/05_of_spades.svg/800px-05_of_spades.svg.png',
    isOpen: false
  },
  {
    id: 12,
    name: "Six",
    pic: 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/6e/06_of_spades.svg/800px-06_of_spades.svg.png',
    isOpen: false
  }
];
export default MOCK;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step-3&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Then lets create a component name of &lt;strong&gt;Board.js&lt;/strong&gt;.&lt;br&gt;
and the code with logic whick will look like below&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, { useEffect, useState } from "react";
import Data from "../app.mock";

const Board = () =&amp;gt; {
  const [cards, setCards] = useState(Data || []);
  const [firstCard, setFirstCard] = useState();
  const [secondCard, setSecondCard] = useState();

  const setCard = (card) =&amp;gt; {
    setCards(
      cards.map((data) =&amp;gt;
        data.id === card.id ? { ...data, isOpen: !card.isOpen } : data
      )
    );
  };

  const handleClick = (card) =&amp;gt; {
    if (card.isOpen) {
      return;
    }
    if (!firstCard) {
      setFirstCard(card);
      setCard(card);
    } else if (!secondCard) {
      setSecondCard(card);
      setCard(card);
    }
  };
  useEffect(() =&amp;gt; {
    let timeOut;
    if (firstCard?.name !== secondCard?.name) {
      timeOut = setTimeout(() =&amp;gt; {
        setCards(
          cards.map((data) =&amp;gt;
            firstCard?.id === data.id || secondCard?.id === data.id
              ? { ...data, isOpen: !data.isOpen }
              : data
          )
        );
        setFirstCard();
        setSecondCard();
      }, 1000);
    } else {
      setFirstCard();
      setSecondCard();
    }
    return () =&amp;gt; {
      clearTimeout(timeOut);
    };
  }, [secondCard]);

  return (
    &amp;lt;div className="board "&amp;gt;
      {cards &amp;amp;&amp;amp;
        Array.isArray(cards) &amp;amp;&amp;amp;
        cards.length &amp;gt; 0 &amp;amp;&amp;amp;
        cards.map((card, index) =&amp;gt; {
          return (
            &amp;lt;div
              className={`singleCard ${card.isOpen ? "fliped" : "show"}`}
              key={index}
              onClick={() =&amp;gt; handleClick(card)}
            &amp;gt;
              {card.isOpen ? (
                &amp;lt;img src={card.pic} className="font_face" alt="img" /&amp;gt;
              ) : (
                &amp;lt;img
                  src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/23/The_Jolly_Nero.jpg/800px-The_Jolly_Nero.jpg"
                  className="back_face"
                  alt="img"
                /&amp;gt;
              )}
            &amp;lt;/div&amp;gt;
          );
        })}
    &amp;lt;/div&amp;gt;
  );
};
export default Board;

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

&lt;/div&gt;



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

&lt;p&gt;Import &lt;strong&gt;Board&lt;/strong&gt; component to &lt;strong&gt;App.js&lt;/strong&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Board from "./components/Board";
import "./styles.css";

export default function App() {
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;Board /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step-5&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Add css for look and fill in &lt;strong&gt;style.css&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* {
  padding: 0px;
  margin: 0px;
  box-sizing: border-box;
}
.App {
  font-family: sans-serif;
  display: flex;
  align-self: center;
  text-align: center;
  justify-content: center;
  height: 100vh;
  background-color: azure;
}
.board {
  display: flex;
  align-self: center;
  justify-content: center;
  flex-wrap: wrap;
  justify-content: flex-start;
  margin: 0 -10px;
  max-width: 500px;
  perspective: 1000px;
}
.singleCard {
  width: 100px;
  height: 120px;
  display: flex;
  margin: 10px;
  /* border: 1px solid gray; */
  border-radius: 5px;
  overflow: hidden;
  justify-content: center;
  cursor: pointer;
  /* padding: 4px; */
  /* background-color: #ffff; */
  transition: all 0.5s;
  transform-style: preserve-3d;
  transform: scale(1);
}
.fliped {
  transform: rotateY(180deg);
}
.font_face {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.back_face {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border: 1px solid black;
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Folder Structure&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Finally our folder structure will look like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K-eEnccV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9nnf7obxncsvkk4gy9nx.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K-eEnccV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9nnf7obxncsvkk4gy9nx.JPG" alt="Image description" width="260" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The End&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KrqpSFVt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f7s16nlbzqgnmnlfc9sf.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KrqpSFVt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f7s16nlbzqgnmnlfc9sf.gif" alt="memory card game" width="800" height="800"&gt;&lt;/a&gt;&lt;br&gt;
That's all  we are ready to play the game..&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>game</category>
    </item>
    <item>
      <title>Using Axios In React JS....</title>
      <dc:creator>Krushna Chandra Dash</dc:creator>
      <pubDate>Wed, 19 Apr 2023 05:19:19 +0000</pubDate>
      <link>https://forem.com/krushnachandradash654/using-axios-in-react-js-4d06</link>
      <guid>https://forem.com/krushnachandradash654/using-axios-in-react-js-4d06</guid>
      <description>&lt;p&gt;Hi Friends.. Let me help you to understand and use axios in react js application. So I am writing this post by considering that you guys know about react js(If don't please gather some knowledge regarding &lt;a href="https://react.dev/"&gt;react js&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What Is Axios?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Axios is a popular JavaScript library used for making HTTP request from a web browser or Node.Js.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Whether you're building a web app or a server-side application, Axios makes is easy to work with &lt;strong&gt;APIs&lt;/strong&gt; and other &lt;strong&gt;HTTP services&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In this post, We will show you how to get get started with Axios, from installing to making basic &lt;strong&gt;GET&lt;/strong&gt; and &lt;strong&gt;POST&lt;/strong&gt; requests and also how to handle error by using async/await syntax.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Setting Up Axios&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To start using Axios you'll need to install it in your project. You can do this using NPM or YARN.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/axios"&gt;&lt;em&gt;For NPM User-&amp;gt;&lt;/em&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://yarnpkg.com/package/axios"&gt;&lt;em&gt;For YARN User-&amp;gt;&lt;/em&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After Installing axios you need to use/ Import it your project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import axios from 'axios';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Basic GET Request&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To make a simple &lt;strong&gt;GET&lt;/strong&gt; request to fetch data&lt;br&gt;
&lt;/p&gt;

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

axios.get('URL')
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .finally(function () {
    // always executed
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// using async and await

async function getUser() {
  try {
    const response = await axios.get('URL');
    console.log(response);
  } catch (error) {
    console.error(error);
  }
}

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Basic POST Request&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When we need to send some data to server we use POST request.&lt;br&gt;
To make a simple &lt;strong&gt;POST&lt;/strong&gt; request to fetch data&lt;br&gt;
In post request usually user send data to server and we call it as request body and server gives response.&lt;br&gt;
&lt;/p&gt;

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

const MY_URL="https://jsonplaceholder.typicode.com/todos/5"
const data = {
 userId: 1,
 id: 5,
 title: “hello task”,
 completed: false
};
axios.post(MY_URL,JSON.stringify(data ))
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .finally(function () {
    // always executed
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// using async and await
const MY_URL="https://jsonplaceholder.typicode.com/todos/5"
const data = {
 userId: 1,
 id: 5,
 title: “hello task”,
 completed: false
};
async function getUser() {
 try {
  const response = await axios.post(MY_URL,JSON.stringify(data ));
    console.log(response);
  } catch (error) {
    console.error(error);
  }
}

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Basic PUT Request&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The PUT method is most often used to update an existing resource. If you want to update a specific resource (which comes with a specific URI), you can call the PUT method to that resource URI with the request body containing the complete new version of the resource you are trying to update.&lt;br&gt;
&lt;/p&gt;

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

const MY_URL="https://jsonplaceholder.typicode.com/todos/5"
const data = {
 userId: 1,
 id: 5,
 title: “hello task”,
 completed: false
};
axios.put(MY_URL,JSON.stringify(data ))
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .finally(function () {
    // always executed
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// using async and await
const MY_URL="https://jsonplaceholder.typicode.com/todos/5"
const data = {
 userId: 1,
 id: 5,
 title: “hello task”,
 completed: false
};
async function editUser() {
  try {
   const response = await axios.put(MY_URL,JSON.stringify(data ));
    console.log(response);
  } catch (error) {
    console.error(error);
  }
}

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Basic Delete Request&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The DELETE method is used to delete a resource specified by its URI.&lt;br&gt;
&lt;/p&gt;

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

const MY_URL="https://jsonplaceholder.typicode.com/todos/5"
axios.delete(MY_URL)
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .finally(function () {
    // always executed
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OR&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// using async and await
const MY_URL="https://jsonplaceholder.typicode.com/todos/5"
async function deleteUser() {
  try {
    const response = await axios.put(MY_URL);
    console.log(response);
  } catch (error) {
    console.error(error);
  }
}

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

&lt;/div&gt;



&lt;p&gt;This document only cover basic use case.. As Axios is a very powerful tool that we can use it in advance case also..  &lt;/p&gt;

</description>
      <category>react</category>
      <category>axios</category>
      <category>database</category>
    </item>
  </channel>
</rss>
