<?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: Sagar Kattel</title>
    <description>The latest articles on DEV Community by Sagar Kattel (@sagarkattel).</description>
    <link>https://dev.to/sagarkattel</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%2F1003552%2F59f71dc3-a483-4645-9be4-bca5c19da22a.jpeg</url>
      <title>DEV Community: Sagar Kattel</title>
      <link>https://dev.to/sagarkattel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sagarkattel"/>
    <language>en</language>
    <item>
      <title>Learn PHP</title>
      <dc:creator>Sagar Kattel</dc:creator>
      <pubDate>Wed, 17 Jan 2024 04:30:17 +0000</pubDate>
      <link>https://dev.to/sagarkattel/learn-php-2ace</link>
      <guid>https://dev.to/sagarkattel/learn-php-2ace</guid>
      <description>&lt;p&gt;Although php language seems to be dying, it is still used by many companies and is widely popular among the legacy codebases of many large companies. It was the language that give rise to the current web development field. Learning PHP can also help you alot in your carrier. I guess these motivation is enough for you guys to start learning the php. So let's get started.&lt;/p&gt;

&lt;p&gt;Let's learn from the fundamentals.&lt;/p&gt;

&lt;p&gt;If you have seen my previous articles i follow certain pattern to learning new languages or framework. This pattern is aiding me to successfully learn the languages.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Give Output and take Input&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;String&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Array&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Class and Object&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Methods&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Loops&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I always follow this pattern to learn any languages. So without further a do let's get started.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1) Give Output and take Input&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The command line used to give output in the php is simple&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;?
echo "Hello world";
//or
print_r("Hello World");
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And to take the input we enclosed it inside readlines&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;?
$name=readline("Enter the name\n");
echo "The name is $name";
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2) String and Variable&lt;/strong&gt;&lt;br&gt;
In PHP to create a string is as simple way as writing variable name starting with $ symbol.&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;?
echo strlen("Hello World");
echo str_word_count("Hello world!");
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Iterating in loop inside the string&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;?
$name="Sagarkattel";
for($i=0;$i&amp;lt;strlen($name);$i++){
    echo "Index of ".$i."="."$name[$i]\n";
}
?&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;For Splitting the string in PHP we use built-in explode function.&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;?
$name="Sagar kattel";
$parts=explode(" ",$name);
echo $parts[0];
echo "\n";
echo $parts[1];
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3) Arrays&lt;/strong&gt;&lt;br&gt;
In php the way to iterate the array is as simple as any other language. Just you need to put $ symbol ahead of every variable name or array.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$names=["Sagar","Saurabh"];&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4) Class and Object&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Creating classes in Php is dead simple, it is as same as other language. The only thing that you need to take care is to write instead of this.name you need to write this-&amp;gt;name.&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;?php
class Fruit {
  public $name;
  public $color;

  function __construct($name, $color) {
    $this-&amp;gt;name = $name;
    $this-&amp;gt;color = $color;
  }
  function get_name() {
    return $this-&amp;gt;name;
  }
  function get_color() {
    return $this-&amp;gt;color;
  }
}

$apple = new Fruit("Apple", "red");
echo $apple-&amp;gt;get_name();
echo "&amp;lt;br&amp;gt;";
echo $apple-&amp;gt;get_color();
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
class Person{
    public $name;
    public $age;

    function __construct($name,$age){
        $this-&amp;gt;name=$name;
        $this-&amp;gt;age=$age;
    }
    function get_name(){
        return $this-&amp;gt;name;
    }

    function get_age(){
        return $this-&amp;gt;age;
    }
}
$name=new Person("Sagar Kattel",20);
echo $name-&amp;gt;get_name();
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Method or Function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can create method or function in php by writing the keyword function ahead of every function name.&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;?php
echo "Hello WOrld";

function speak_name($name){
    echo "The name of our hero is ".$name;
}
$number1=20;

function multiply($number){
    return $number*2;
}

$name="Sagar Kattel";
speak_name($name);
$result=multiply(3);
echo "The Multiply result is ".$result
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Loops&lt;/strong&gt;&lt;br&gt;
You can create loops in php as any other programming lanaguages.&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;?php
$i=0;
while($i&amp;lt;10){
    print_r($i);
    $i++;
}
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;These are the basics that you must know before diving deep into the PHP programming language. Hope you continue your learning journey. Sayonara &amp;lt;3&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Create Hello World application in Ruby On Rails</title>
      <dc:creator>Sagar Kattel</dc:creator>
      <pubDate>Mon, 08 Jan 2024 10:52:41 +0000</pubDate>
      <link>https://dev.to/sagarkattel/create-hello-world-application-in-ruby-on-rails-42e8</link>
      <guid>https://dev.to/sagarkattel/create-hello-world-application-in-ruby-on-rails-42e8</guid>
      <description>&lt;p&gt;&lt;strong&gt;Hello Folks,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today we are going to learn how to create simple hello world &lt;strong&gt;application&lt;/strong&gt; in ruby on rails. So hold your horses as i *&lt;em&gt;embark *&lt;/em&gt; on you to your journey.&lt;/p&gt;

&lt;p&gt;As you create the ruby on rails application with the command like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
rails new project1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a simple ruby on rails application and now you need to enter inside it and just type&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;to start the server&lt;/p&gt;

&lt;p&gt;Now what you need to do to display the "Hello World" application running is to go to the routes.rb file &lt;/p&gt;

&lt;p&gt;And there specify what you want your routes folder to redirect it to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root "controller_name#action"

root "pages#home"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now you need to create controller and for that you can simply write&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails generate controller pages

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

&lt;/div&gt;



&lt;p&gt;This command will generate pages_controller.rb and will also generate pages folder inside views folder&lt;/p&gt;

&lt;p&gt;And how inside the pages_controller.rb write these code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def home
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will invoke the controller to check the pages/home.html.erb file and display whatever is present there&lt;/p&gt;

&lt;p&gt;And inside the pages folder create home.html.erb file and just type&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;And now you have successfully generated the Hello World Application. Sayonara &amp;lt;3&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Learn Ruby From A to Z</title>
      <dc:creator>Sagar Kattel</dc:creator>
      <pubDate>Sun, 07 Jan 2024 09:03:22 +0000</pubDate>
      <link>https://dev.to/sagarkattel/learn-ruby-from-a-to-z-2kb4</link>
      <guid>https://dev.to/sagarkattel/learn-ruby-from-a-to-z-2kb4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Hello Folks,&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today we are going to learn about one of the popular Programming language &lt;strong&gt;Ruby&lt;/strong&gt;. Here you are going to learn everything about the basic ruby stuffs. You can use this as your documentation for learning Ruby.&lt;/p&gt;

&lt;p&gt;Instead of watching videos about Ruby &lt;strong&gt;I urge you guys to follow the documentation or article&lt;/strong&gt;. I have made this article with the sole purpose that you don't have to visit other website or watch the videos to learn the Ruby programming language basics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So let's get started...&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The most fundamental thing that you need to learn to get started with any programming languages are :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Give Output and take Input&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;2. String&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;3. Array&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;4. Class and Object&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;5. Methods&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;6. Loops&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are able to grasp these concepts of any programming language then you are good to go. So we are going to follow the same pattern in learning Ruby on rails.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Give Output and take Input&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To print the output to the screen there are two ways and they are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;i. puts&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
This is used to print the statement or line and moves onto the next line after its completion&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;ii. print&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
This is used to print the statement or line and doesnot move onto the next line after its completion instead it prints on the same line after it end.&lt;/p&gt;

&lt;p&gt;And to take input in Ruby what you can do is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;puts "What is your name?"
name=gets
puts "Hello #{name}, How are you"

Output:
Hello Sagar
, How are you

This will print like this instead of printing out in same line and for us to obtain it without the the \n we need to get it chomped

puts "What is your name?"
name=gets.chomp
puts "Hello #{name}, How are you"

Output will be:
Hello Sagar, How are you
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. String&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;String are the combination of characters. &lt;br&gt;
To create a string you need to put the characters inside the enclosed single code ''&lt;/p&gt;

&lt;p&gt;&lt;code&gt;str='Hello this is string'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here str is the string. Also String is an inbuilt method for the creation of string and you can create string with this way too.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;str1=String.new("Hello WOrld")
puts str1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To Find the length of string&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;str='Hellostring'
puts str.length

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

&lt;/div&gt;



&lt;p&gt;For iterating through the characters inside the string using for loop&lt;br&gt;
&lt;/p&gt;

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

for i in (0..str1.length)
  puts str1[i]
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For splitting the words in strings after every spacing we use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;str1="Hello World k ca"
puts str1.split
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Array&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are  many ways to create array in Ruby. One of the method is to directly assign an empty array enclosed inside [ ] bracket . And another way is to do it using Array method using new initialize keyword&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;names=Array.new()
# names=[]
names.push("Sagar")
names.push("Kattel")
puts names
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also to insert elements inside array you can either use .push or [index].&lt;/p&gt;

&lt;p&gt;TO find the length of Array also we use .length&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;names.length 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Class and Object&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To create class in Ruby we start with the class keyword followed by its name and the first letter of its name is in uppercase. And it ends with the keyword end&lt;br&gt;
&lt;/p&gt;

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

end

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

&lt;/div&gt;



&lt;p&gt;This is the way we create class.&lt;/p&gt;

&lt;p&gt;Now to create variable in class&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Vehicle
  @@speed=100

  def vehicle_speed()
    @@speed
  end
end

car1=Vehicle.new

puts car1.vehicle_speed()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And during the initialization phase of the creation of class the varible name contains single @ and the variables inside the class gets two @&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Vehicle
  @@speed=100

  def vehicle_speed()
    @@speed
  end

  def initialize(name,country)
    @car_name=name
    @car_country=country
  end

  def define
    puts "The Name of Car is #{@car_name} and it was manufactured in #{@car_country}"
  end

end


mercedes=Vehicle.new("Mercedes","USA")

mercedes.define()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Method or Function&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Method or function is written inside the the def followed by its name in lowercase and ends with the end keyword&lt;/p&gt;

&lt;p&gt;Objects is created to access the variable, or method of inside the class. Object is the instance of class. Objects can be created by following a class name with the dot operator followed by the new keyword.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def greet(name)
  puts "Hello #{name}"
end

greet("Sagar")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Loops&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are many types of loop used inside the Ruby some of them are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;i. For Loop&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Syntax for the use of for loop inside the ruby are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for i in (0..10)
  puts i
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;ii. While do Loop&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Syntax for the use of while do loop inside the ruby are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
$i=0;
$num=5;

while $i&amp;lt;$num do
  puts $i
  $i+=1
end 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;iii. Each do loop&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Syntax for the use of each do loop inside the ruby are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(0..5).each do |i|
  puts i
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;These are the basics that you must know before diving deep into the ruby programming language.&amp;lt;3&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Responsive Navbar with light/dark toggle button Using React</title>
      <dc:creator>Sagar Kattel</dc:creator>
      <pubDate>Mon, 06 Nov 2023 09:42:29 +0000</pubDate>
      <link>https://dev.to/sagarkattel/responsive-navbar-with-lightdark-toggle-button-using-react-1h86</link>
      <guid>https://dev.to/sagarkattel/responsive-navbar-with-lightdark-toggle-button-using-react-1h86</guid>
      <description>&lt;p&gt;Hello Folks, &lt;strong&gt;today&lt;/strong&gt; we are going to setup Responsive &lt;strong&gt;Navbar&lt;/strong&gt; with a toggle button to switch between &lt;strong&gt;dark mode&lt;/strong&gt; and &lt;strong&gt;light mode&lt;/strong&gt; using useContext hook.&lt;/p&gt;

&lt;p&gt;As I have &lt;strong&gt;promised&lt;/strong&gt; you guys to bring more content on the topic &lt;strong&gt;useContext&lt;/strong&gt; hook so here we are, learning in &lt;strong&gt;depth&lt;/strong&gt; about it. Follow me to get constant &lt;strong&gt;updates&lt;/strong&gt; like this to enrich your knowledge.&lt;/p&gt;

&lt;p&gt;As we know setting Navbar with a &lt;strong&gt;responsive&lt;/strong&gt; design can be a hectic task if you are planning to build a &lt;strong&gt;large&lt;/strong&gt; website, half of our time goes to setup the navbar and today I am planning to give you guys responsive navbar code to &lt;strong&gt;easily&lt;/strong&gt; code it and just focus to &lt;strong&gt;grab&lt;/strong&gt; the concept of useContext.&lt;/p&gt;

&lt;p&gt;So the &lt;strong&gt;prerequisites&lt;/strong&gt; to setup this navbar is that you need to install &lt;strong&gt;TailwindCSS&lt;/strong&gt; and React.&lt;/p&gt;

&lt;p&gt;If you haven't installed TailwindCSS I request you guys to follow this link &lt;a href="https://tailwindcss.com/docs/guides/create-react-app"&gt;TailwindCSS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you have every prerequisites here is the Responsive Navbar code that you can &lt;strong&gt;include&lt;/strong&gt; it in your React &lt;strong&gt;Project&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;//Navbar.js

import React, { useContext,  useState } from 'react';
import { AiOutlineClose, AiOutlineMenu } from 'react-icons/ai';

import {MdDarkMode} from 'react-icons/md';
import {MdLightMode} from 'react-icons/md';

import { AllContext } from './Context';

const Navbar = () =&amp;gt; {
  const [nav, setNav] = useState(false);



  const {darkmode,handleMode}=useContext(AllContext);



  const handleNav = () =&amp;gt; {
    setNav(!nav);
  };

  return (
    &amp;lt;div className='flex justify-between items-center h-24 max-w-[1240px] mx-auto px-4 text-white '&amp;gt;
      &amp;lt;h1 className='w-full text-3xl font-bold text-[#00df9a] cursor-pointer'&amp;gt;REACT.&amp;lt;/h1&amp;gt;
      &amp;lt;ul className='hidden md:flex cursor-pointer'&amp;gt;
        &amp;lt;li className='p-4'&amp;gt;Home&amp;lt;/li&amp;gt;
        &amp;lt;li className='p-4'&amp;gt;Company&amp;lt;/li&amp;gt;
        &amp;lt;li className='p-4'&amp;gt;Resources&amp;lt;/li&amp;gt;
        &amp;lt;li className='p-4'&amp;gt;About&amp;lt;/li&amp;gt;
        &amp;lt;li className='p-4' onClick={handleMode}&amp;gt;{darkmode?&amp;lt;MdLightMode size={25}/&amp;gt;:&amp;lt;MdDarkMode size={25}/&amp;gt;}&amp;lt;/li&amp;gt;
      &amp;lt;/ul&amp;gt;
      &amp;lt;div onClick={handleNav} className='block md:hidden'&amp;gt;
          {nav ? &amp;lt;AiOutlineClose size={20}/&amp;gt; : &amp;lt;AiOutlineMenu size={20} /&amp;gt;}
      &amp;lt;/div&amp;gt;
      &amp;lt;ul className={nav ? 'fixed left-0 top-0 w-[60%] h-full border-r border-r-gray-900 bg-[#000300] ease-in-out duration-500' : 'ease-in-out duration-500 fixed left-[-100%]'}&amp;gt;
        &amp;lt;h1 className='w-full text-3xl font-bold text-[#00df9a] m-4 '&amp;gt;REACT.&amp;lt;/h1&amp;gt;
          &amp;lt;li className='p-4 border-b border-gray-600'&amp;gt;Home&amp;lt;/li&amp;gt;
          &amp;lt;li className='p-4 border-b border-gray-600'&amp;gt;Company&amp;lt;/li&amp;gt;
          &amp;lt;li className='p-4 border-b border-gray-600'&amp;gt;Resources&amp;lt;/li&amp;gt;
          &amp;lt;li className='p-4 border-b border-gray-600'&amp;gt;About&amp;lt;/li&amp;gt;
          &amp;lt;li className='p-4'&amp;gt;Contact&amp;lt;/li&amp;gt;
      &amp;lt;/ul&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Navbar;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will enable you to &lt;strong&gt;access&lt;/strong&gt; Responsive Navbar with &lt;strong&gt;Light/Dark&lt;/strong&gt; Toggle button.&lt;/p&gt;

&lt;p&gt;Now let's come to our Main topic &lt;strong&gt;useContext&lt;/strong&gt; hook. As you might have &lt;strong&gt;already&lt;/strong&gt; notice that in our code we used useContext hook to access darkMode and setDarkMode. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;useContext&lt;/strong&gt; hook is also prop &lt;strong&gt;drilling&lt;/strong&gt; approach of &lt;strong&gt;parsing&lt;/strong&gt; of data across the pages in React. It simply &lt;strong&gt;means&lt;/strong&gt; data are passed around the different pages/component based on the &lt;strong&gt;hierarchy&lt;/strong&gt; (Means Top to button approach also means Parent to Child data transfer). &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It simply means if a data is &lt;strong&gt;passed&lt;/strong&gt; through any component then it's &lt;strong&gt;child component&lt;/strong&gt; or nested components inside that components can easily access that data. Clear Enough Right?&lt;/p&gt;

&lt;p&gt;For Visualization of this concept &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--h6DAqZLs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53gnj862ykd5jc4ymb55.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h6DAqZLs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/53gnj862ykd5jc4ymb55.PNG" alt="useContext Visualization" width="443" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here We fetched the &lt;strong&gt;login&lt;/strong&gt; credentials in App Component and Since App component is at the Top level of any React Application and &lt;strong&gt;Component A&lt;/strong&gt; (User Page) is the child component so login &lt;strong&gt;credentials&lt;/strong&gt; is passed from App page to Component A page using useContext hook.&lt;/p&gt;

&lt;p&gt;So useContext code for our &lt;strong&gt;Responsive&lt;/strong&gt; Navbar for the light/dark toggle &lt;strong&gt;functionality&lt;/strong&gt; is:&lt;br&gt;
&lt;/p&gt;

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

import React, { createContext, useEffect, useState } from "react";

export const AllContext = createContext(null);



  const Context = ({ children }) =&amp;gt; {

    const [darkmode,setDarkmode]=useState(false);

    const handleMode=()=&amp;gt;{
        setDarkmode(!darkmode)
    }


    return (
      &amp;lt;AllContext.Provider
        value={{darkmode,setDarkmode,handleMode}}
      &amp;gt;
        {children}
      &amp;lt;/AllContext.Provider&amp;gt;
    );
  };

  export default Context;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So here we have used useState hook in the &lt;strong&gt;context.js&lt;/strong&gt; page to do the toggle and simply pass that &lt;strong&gt;toggle&lt;/strong&gt; value in the component &lt;code&gt;&amp;lt;AllContext.Provider&amp;gt;&lt;/code&gt;. And you can access that toggled value in Navbar using useContext as shown in the &lt;code&gt;Navbar.js&lt;/code&gt; page&lt;/p&gt;

&lt;p&gt;Now, we Simply &lt;strong&gt;wrap&lt;/strong&gt; the Context Component in the Top of our &lt;strong&gt;Application&lt;/strong&gt; 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;
//Main.js

import App from "./App";
import Context from './Context'

export default function Main() {
  return (
   &amp;lt;Context&amp;gt;
      &amp;lt;App /&amp;gt;
   &amp;lt;/Context&amp;gt;
  )
}


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

&lt;/div&gt;



&lt;p&gt;In this way, you can use &lt;strong&gt;useContext&lt;/strong&gt; hook in your application. If you have any problem please &lt;strong&gt;comment&lt;/strong&gt; it out i am more than happy to help and don't forget to like and follow.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Sayonaraa!&lt;/strong&gt;😉&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Let's Learn Redux (Complete Tutorial)</title>
      <dc:creator>Sagar Kattel</dc:creator>
      <pubDate>Thu, 02 Nov 2023 17:49:59 +0000</pubDate>
      <link>https://dev.to/sagarkattel/lets-learn-redux-complete-tutorial-1iem</link>
      <guid>https://dev.to/sagarkattel/lets-learn-redux-complete-tutorial-1iem</guid>
      <description>&lt;p&gt;Basically when you are starting out your career in &lt;strong&gt;React&lt;/strong&gt; development field, you must have stumble upon the concept of Redux. And it might seem &lt;strong&gt;tedious&lt;/strong&gt; and so much &lt;strong&gt;boilercode&lt;/strong&gt; that it can even demotivate you on your journey. But i am here to rescue you to learn those concept in &lt;strong&gt;breeze&lt;/strong&gt; and in simple language as well so hold your horses as i embark you on the journey to completely learn Redux.&lt;/p&gt;

&lt;p&gt;So let's start with its definition:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Redux is a very popular JavaScript library that is designed to manage the state of data in JavaScript applications&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Also you must have stumble upon the work state of data but what does the state of data refers? &lt;br&gt;
It simply means :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A state in Redux is a JavaScript object, where the internal state of the application is stored as its properties&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This definition also seems kind of &lt;strong&gt;vague&lt;/strong&gt; representation for you guys but let me explain it to you using &lt;strong&gt;simple&lt;/strong&gt; words using an working example as it can help you wrap around the concept  more easily. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When we login into an website, we get the login detail and we might want to pass that details to different pages within the &lt;strong&gt;website&lt;/strong&gt;. We can't fetch the login details in every page as fetching Api's can be quite expensive. In the practical &lt;strong&gt;scenario&lt;/strong&gt; we fetch the &lt;strong&gt;Api&lt;/strong&gt; once and keep its data somewhere in the client side and send the data in every page.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Generally there are two ways to store data and to pass on that data to every page i.e &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use useContext hook&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Redux hook&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;useContext&lt;/strong&gt; hooks works on the principle of &lt;strong&gt;prop drilling&lt;/strong&gt;. It means it passes the data based on the hierarchy. In computer terminology, data is passed from the parent component to its child component which also refers to top-down &lt;strong&gt;approach&lt;/strong&gt;. Here in this approach we fetch the data from the Api once then we pass the data to the useContext page and we put the useContext hook in the top level of the application then the data can be accessed in every page &lt;strong&gt;subsequent&lt;/strong&gt; to its child page. Simple enough right? If you are stuck here i will do deep &lt;strong&gt;dive&lt;/strong&gt; related to it in another article. Also i will show you how to implement it in our application. Our sole focus today is to make you understand about Redux concept.&lt;/p&gt;

&lt;p&gt;Redux on the other hand is another &lt;strong&gt;hook&lt;/strong&gt; that also works on the principle of prop drilling. It consits of 3 parts i.e&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Store&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reducers&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dispatch and Selector&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Redux store is the main, central bucket which stores all the states of an application. It should be considered and maintained as a single source of truth for the state of the application.&lt;br&gt;
If the store is provided to the &lt;code&gt;App.js&lt;/code&gt; (by wrapping the App component within the &lt;code&gt;&amp;lt;Provider&amp;gt; &amp;lt;/Provider&amp;gt;&lt;/code&gt; tag) as shown in the code snippet below, then all its children (children components of App.js) can also access the state of the &lt;strong&gt;application&lt;/strong&gt; from the store. This makes it act as a global state.&lt;/p&gt;

&lt;p&gt;Let's create an application to even understand it further with its implementation detail. Here for our simplicity, we take an example of &lt;strong&gt;Ecommerce&lt;/strong&gt; Cart System.&lt;/p&gt;

&lt;p&gt;At first Create Provider for the store in our application. This will ensure that the data from the store are &lt;strong&gt;drilled&lt;/strong&gt; down at the top level i.e index page and it's subsequent page i.e &lt;strong&gt;App&lt;/strong&gt; page can access the data. App contains further collection of pages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
// src/index.ts

import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'

import { App } from './App'
import createStore from './createReduxStore'

import { store } from "./store";

// As of React 18
const root = ReactDOM.createRoot(document.getElementById('root'))
root.render(
  &amp;lt;Provider store={store}&amp;gt;
    &amp;lt;App /&amp;gt;
  &amp;lt;/Provider&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Meanwhile create store that manages the application along with the Reducers and &lt;strong&gt;dispatch&lt;/strong&gt; and &lt;strong&gt;selector&lt;/strong&gt; function. Store consists of configureStore function to initialize the reducers along with &lt;strong&gt;setupListeners&lt;/strong&gt; functions. Also we initialize the dispatch function in the name of &lt;strong&gt;AppDispatch&lt;/strong&gt; and export it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//store.ts


import { configureStore } from '@reduxjs/toolkit';

import productSlice from './features/productSlice';

export const store = configureStore({
    reducer: {
      product:productSlice,
    }
  })

  setupListeners(store.dispatch);


  // Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType&amp;lt;typeof store.getState&amp;gt;
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
export type AppDispatch = typeof store.dispatch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's create &lt;strong&gt;productSlice&lt;/strong&gt; feature for our react application which is also known as &lt;strong&gt;Reducers&lt;/strong&gt; here in redux concept.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
//productSlice.ts

import { createSlice, PayloadAction } from "@reduxjs/toolkit";

export interface ProductProp {
  id: number;
  title: string;
  img_url: string;
  price: number;
  rating: number;
  quantity: number;
}

interface ProductState {
  products: ProductProp[];
}

const initialState: ProductState = {
  products: [],
};

export const productSlice = createSlice({
  name: "product",
  initialState,
  reducers: {
    addProduct: (state, action) =&amp;gt; {
      const product = action.payload;

      // Check if a product with the same ID already exists in the state.products array
      const existingProductIndex = state.products.findIndex(
        (existingProduct) =&amp;gt; existingProduct.id === product.id
      );
      if (existingProductIndex !== -1) {
        console.log("Product Already Exists");
        state.products[existingProductIndex].quantity += 1;
      } else {
        // If no product with the same ID exists, add the product to the array
        state.products.push({ ...product, quantity: 1 });
      }
    },
    removeProduct: (state, action) =&amp;gt; {
      const productload = action.payload;
      state.products = state.products.filter(
        (product) =&amp;gt; product.id !== productload
      );
    },
  },
});

export const { addProduct, removeProduct } = productSlice.actions;

export default productSlice.reducer;

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

&lt;/div&gt;



&lt;p&gt;This is it now you have &lt;strong&gt;successfully&lt;/strong&gt; configured the store along with the actions. Now all you have to do is call &lt;strong&gt;useDispatch&lt;/strong&gt; and &lt;strong&gt;useSelector&lt;/strong&gt; to perform the actions. Let's take a peek to how can we achieve it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Card.tsx

import { useAppDispatch, useAppSelector } from "@/redux/hooks";
import { addProduct } from "@/redux/features/productSlice";


const dispatch=useAppDispatch();

const Card=()=&amp;gt;{

const [productsList, setProducts] = React.useState([]);


  const handleClick=(product:productT)=&amp;gt;{
    dispatch(addProduct(product))
    console.log(product)
  }


return(
&amp;lt;div&amp;gt;
 {products.map((product)=&amp;gt;(

&amp;lt;div key={product.id}&amp;gt;
&amp;lt;button onClick={()=&amp;gt;handleClick(product)}&amp;gt; Add to Cart &amp;lt;/button&amp;gt;
&amp;lt;/div&amp;gt;
))}

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

export default Card;

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

&lt;/div&gt;



&lt;p&gt;Here using useAppDispatch, we call the function &lt;strong&gt;addProduct&lt;/strong&gt; reducers to perform the actions and pass value into it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Cart.tsx

import { useAppDispatch, useAppSelector } from "@/redux/hooks";
import { ProductProp, removeProduct } from "@/redux/features/productSlice";


const Cart=()=&amp;gt;{

const dispatch=useAppDispatch();

const products:ProductProp[] = useAppSelector((state:any) =&amp;gt; state.product.products);


return(
&amp;lt;div&amp;gt;
 {products.map((product)=&amp;gt;(

&amp;lt;div key={product.id}&amp;gt;

&amp;lt;button onClick={(event) =&amp;gt; dispatch(removeProduct(product.id))}&amp;gt;Remove&amp;lt;/button&amp;gt;
&amp;lt;/div&amp;gt;
))}

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

export default Cart;


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

&lt;/div&gt;



&lt;p&gt;Here we first view the products that we obtain from the the the &lt;strong&gt;store&lt;/strong&gt; using &lt;strong&gt;useAppSelector&lt;/strong&gt; as it helps to view the data stored in store in the name products and &lt;strong&gt;map&lt;/strong&gt; it out then we perform the necessary dispatch to modify the data in the store with the help of reducers.&lt;/p&gt;

&lt;p&gt;This is the perfect &lt;strong&gt;representation&lt;/strong&gt; of the application of &lt;strong&gt;Redux&lt;/strong&gt;. I hope this gives you in-depth understanding on this subject matter of &lt;strong&gt;Redux&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Sayonara&lt;/strong&gt;😉! (The word sayonara means "goodbye" or "farewell.")&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>react</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
