<?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: Dipayan Das</title>
    <description>The latest articles on Forem by Dipayan Das (@dipayandas24).</description>
    <link>https://forem.com/dipayandas24</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%2F1137574%2F1e35739a-6d5f-48bb-88eb-4868191ca8cf.png</url>
      <title>Forem: Dipayan Das</title>
      <link>https://forem.com/dipayandas24</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/dipayandas24"/>
    <language>en</language>
    <item>
      <title>DRepo: A Decentralized Version Control System- Day 3</title>
      <dc:creator>Dipayan Das</dc:creator>
      <pubDate>Mon, 18 Dec 2023 19:57:32 +0000</pubDate>
      <link>https://forem.com/dipayandas24/drepo-a-decentralized-version-control-system-day-3-4cep</link>
      <guid>https://forem.com/dipayandas24/drepo-a-decentralized-version-control-system-day-3-4cep</guid>
      <description>&lt;p&gt;In this section, we are going to learn the basics of JavaScript and then we will move forward to React. And at the end, we will be doing out main Project Installation Part.&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;JavaScript is the world's most popular programming language.&lt;br&gt;
JavaScript is the programming language of the Web.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Why Study JavaScript?
&lt;/h3&gt;

&lt;p&gt;JavaScript is one of the 3 languages all web developers must learn:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;HTML&lt;/strong&gt; to define the content of web pages&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CSS&lt;/strong&gt; to specify the layout of web pages&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JavaScript&lt;/strong&gt; to program the behavior of web pages&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  JavaScript Can Change HTML Content
&lt;/h3&gt;

&lt;p&gt;One of many JavaScript HTML methods is &lt;code&gt;getElementById().&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The example below "finds" an HTML element (with id="demo"), and changes the element content (innerHTML) to "Hello World":&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;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;h2&amp;gt;What Can JavaScript Do?&amp;lt;/h2&amp;gt;

&amp;lt;p id="demo"&amp;gt;JavaScript can change HTML content.&amp;lt;/p&amp;gt;

&amp;lt;button type="button" onclick='document.getElementById("demo").innerHTML = "Hello World"'&amp;gt;Click Me!&amp;lt;/button&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  JavaScript Where To
&lt;/h3&gt;

&lt;h4&gt;
  
  
  The &lt;code&gt;script&lt;/code&gt; Tag
&lt;/h4&gt;

&lt;p&gt;In HTML, JavaScript code is inserted between &lt;br&gt;
&lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;/script&amp;gt;&lt;/code&gt; tags.&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;script&amp;gt;
document.getElementById("demo").innerHTML = "My First JavaScript";
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  JavaScript Functions and Events
&lt;/h2&gt;

&lt;p&gt;A JavaScript &lt;code&gt;function&lt;/code&gt; is a block of JavaScript code, that can be executed when "called" for.&lt;/p&gt;

&lt;p&gt;For example, a function can be called when an event occurs, like when the user clicks a button.&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript in  or 
&lt;/h2&gt;

&lt;p&gt;You can place any number of scripts in an HTML document.&lt;/p&gt;

&lt;p&gt;Scripts can be placed in the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt;, or in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; section of an HTML page, or in both, depending upon the purpose or requirement.&lt;/p&gt;

&lt;h2&gt;
  
  
  External JavaScript
&lt;/h2&gt;

&lt;p&gt;External scripts are practical when the same code is used in many different web pages.&lt;/p&gt;

&lt;p&gt;JavaScript files have the file extension &lt;strong&gt;.js&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To use an external script, put the name of the script file in the &lt;code&gt;src&lt;/code&gt; (source) attribute of a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag:&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;script src="myScript.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  JavaScript Output
&lt;/h2&gt;

&lt;h3&gt;
  
  
  JavaScript Display Possibilities
&lt;/h3&gt;

&lt;p&gt;JavaScript can "display" data in different ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Writing into an HTML element, using &lt;code&gt;innerHTML&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Writing into the HTML output using &lt;code&gt;document.write().&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Writing into an alert box, using &lt;code&gt;window.alert().&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Writing into the browser console, &lt;code&gt;using console.log().&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  JavaScript Keywords
&lt;/h2&gt;

&lt;p&gt;JavaScript statements often start with a keyword to identify the JavaScript action to be performed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Keyword Description
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;var           - Declares a variable&lt;/li&gt;
&lt;li&gt;let           - Declares a block variable&lt;/li&gt;
&lt;li&gt;const         - Declares a block constant&lt;/li&gt;
&lt;li&gt;if            - Marks a block of statements to be executed on a 
            -condition&lt;/li&gt;
&lt;li&gt;switch    - Marks a block of statements to be executed in 
            different cases&lt;/li&gt;
&lt;li&gt;for           - Marks a block of statements to be executed in a 
            loop&lt;/li&gt;
&lt;li&gt;function  - Declares a function&lt;/li&gt;
&lt;li&gt;return    - Exits a function&lt;/li&gt;
&lt;li&gt;try           - Implements error handling to a block of statements&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  JavaScript Variables
&lt;/h2&gt;

&lt;p&gt;In a programming language, variables are used to store data values.&lt;br&gt;
JavaScript uses the keywords var, let and const to declare variables.&lt;br&gt;
An equal sign is used to assign values to variables.&lt;/p&gt;

&lt;p&gt;In this example, x is defined as a variable. Then, x is assigned (given) the value 6:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let x;
x = 6;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Variables and Data Types
&lt;/h3&gt;

&lt;p&gt;JavaScript uses variables to store and manipulate data. Variables are declared using the let or const keyword.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let&lt;/code&gt; is used for variables that can be reassigned.&lt;br&gt;
&lt;code&gt;const&lt;/code&gt; is used for variables that should not be reassigned.&lt;br&gt;
The &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; keywords were added to JavaScript in 2015.&lt;br&gt;
The &lt;code&gt;var&lt;/code&gt; keyword should only be used in code written for older browsers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let message = "Hello, World!";
const pi = 3.14;
let isTrue = true;
let fruits = ["apple", "orange", "banana"];
let person = { name: "John", age: 30 };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above:&lt;/p&gt;

&lt;p&gt;message is a string variable.&lt;br&gt;
pi is a constant representing the mathematical constant Pi.&lt;br&gt;
isTrue is a boolean variable.&lt;br&gt;
fruits is an array containing strings.&lt;br&gt;
person is an object with properties name and age.&lt;/p&gt;
&lt;h2&gt;
  
  
  JavaScript Const
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Variables defined with &lt;code&gt;const&lt;/code&gt; cannot be &lt;strong&gt;Redeclared&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Variables defined with &lt;code&gt;const&lt;/code&gt; cannot be &lt;strong&gt;Reassigned&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Variables defined with &lt;code&gt;const&lt;/code&gt; have &lt;strong&gt;Block Scope&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JavaScript has two types of scope:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Global Scope:&lt;/strong&gt; Variables declared outside of a function are in the global scope and can be accessed throughout the entire program.&lt;br&gt;
&lt;strong&gt;Local Scope:&lt;/strong&gt; Variables declared inside a function are in the local scope and can only be accessed within that function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript Data Types&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript has 8 Datatypes&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;li&gt;Number&lt;/li&gt;
&lt;li&gt;Bigint&lt;/li&gt;
&lt;li&gt;Boolean&lt;/li&gt;
&lt;li&gt;Undefined&lt;/li&gt;
&lt;li&gt;Null&lt;/li&gt;
&lt;li&gt;Symbol&lt;/li&gt;
&lt;li&gt;Object&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;The Object Datatype&lt;br&gt;
The object data type can contain:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;An object&lt;/li&gt;
&lt;li&gt;An array&lt;/li&gt;
&lt;li&gt;A date&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  JavaScript Functions
&lt;/h2&gt;

&lt;p&gt;A JavaScript function is a block of code designed to perform a particular task.&lt;br&gt;
A JavaScript function is executed when "something" invokes it (calls it).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet(name) {
  let greeting = "Hello, " + name + "!";
  return greeting;
}

console.log(greet("TDoC")); // Output: Hello, TDoC!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, greet is a function that takes a parameter name and returns a greeting.&lt;/p&gt;

&lt;h3&gt;
  
  
  JavaScript Function Syntax
&lt;/h3&gt;

&lt;p&gt;A JavaScript &lt;code&gt;function&lt;/code&gt; is defined with the function keyword, followed by a name, followed by parentheses ().&lt;/p&gt;

&lt;p&gt;The code to be executed, by the function, is placed inside curly brackets: {}&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function name(parameter1, parameter2, parameter3) {
  // code to be executed
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Function parameters are listed inside the parentheses () in the function definition.&lt;/li&gt;
&lt;li&gt;Function arguments are the values received by the function when it is invoked.&lt;/li&gt;
&lt;li&gt;Inside the function, the arguments (the parameters) behave as local variables.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Function Invocation
&lt;/h4&gt;

&lt;p&gt;The code inside the function will execute when "something" invokes (calls) the function:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When an event occurs (when a user clicks a button)&lt;/li&gt;
&lt;li&gt;When it is invoked (called) from JavaScript code&lt;/li&gt;
&lt;li&gt;Automatically (self invoked)&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Function Return
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;When JavaScript reaches a &lt;code&gt;return&lt;/code&gt; statement, the function will stop executing.&lt;/li&gt;
&lt;li&gt;If the function was invoked from a statement, JavaScript will "return" to execute the code after the invoking statement.&lt;/li&gt;
&lt;li&gt;Functions often compute a return value. The return value is "returned" back to the "caller":
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Function is called, the return value will end up in x
let x = myFunction(4, 3);

function myFunction(a, b) {
// Function returns the product of a and b
  return a * b;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Control Flow: Conditional Statements and Loops
&lt;/h2&gt;

&lt;h3&gt;
  
  
  JavaScript if, else, and else if
&lt;/h3&gt;

&lt;p&gt;Conditional statements are used to perform different actions based on different conditions.&lt;/p&gt;

&lt;p&gt;In JavaScript we have the following conditional statements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;if&lt;/code&gt; to specify a block of code to be executed, if a specified condition is true&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;else&lt;/code&gt; to specify a block of code to be executed, if the same condition is false&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;else if&lt;/code&gt; to specify a new condition to test, if the first condition is false&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;switch&lt;/code&gt; to specify many alternative blocks of code to be executed&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  JavaScript Loops
&lt;/h3&gt;

&lt;p&gt;Loops can execute a block of code a number of times.&lt;/p&gt;

&lt;h4&gt;
  
  
  Different Kinds of Loops
&lt;/h4&gt;

&lt;p&gt;JavaScript supports different kinds of loops:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;for&lt;/code&gt; - loops through a block of code a number of times&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;for/in&lt;/code&gt; - loops through the properties of an object&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;for/of&lt;/code&gt; - loops through the values of an iterable object&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;while&lt;/code&gt; - loops through a block of code while a specified condition is true&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;do/while&lt;/code&gt; - also loops through a block of code while a specified condition is true
&lt;/li&gt;
&lt;/ul&gt;

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

if (num &amp;gt; 0) {
  console.log("Positive number");
} else if (num &amp;lt; 0) {
  console.log("Negative number");
} else {
  console.log("Zero");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Loops, such as for and while, enable repetitive execution of code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i = 0; i &amp;lt; 5; i++) {
  console.log(i);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This loop prints the values 0 through 4 to the console.&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript Callbacks
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A callback is a function passed as an argument to another function&lt;/li&gt;
&lt;li&gt;This technique allows a function to call another function&lt;/li&gt;
&lt;li&gt;A callback function can run after another function has finished&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Asynchronous Programming
&lt;/h2&gt;

&lt;p&gt;Functions running in parallel with other functions are called asynchronous. JavaScript supports asynchronous programming to handle operations that may take time, like fetching data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Promises
&lt;/h3&gt;

&lt;p&gt;A Promise is an object representing the eventual completion or failure of an asynchronous operation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function fetchData() {
return new Promise((resolve, reject) =&amp;gt; {
setTimeout(() =&amp;gt; {
const data = "Fetched data";
resolve(data);
}, 1000);
});
}

fetchData().then((result) =&amp;gt; {
console.log(result); // Output: Fetched data
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, fetchData returns a promise. When the data is fetched, the resolve function is called.&lt;/p&gt;

&lt;h3&gt;
  
  
  Async/Await
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;async makes a function return a Promise&lt;/li&gt;
&lt;li&gt;await makes a function wait for a Promise
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function fetchDataAsync() {
try {
const result = await fetchData();
console.log(result); // Output: Fetched data
} catch (error) {
console.error(error);
}
}

fetchDataAsync();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The await keyword is used within an async function to wait for the completion of a promise.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;JavaScript EventListener&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  React
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;React is a JavaScript library for building user interfaces.&lt;/li&gt;
&lt;li&gt;React is used to build single-page applications.&lt;/li&gt;
&lt;li&gt;React allows us to create reusable UI components.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can find the official &lt;strong&gt;React&lt;/strong&gt; Documentation &lt;a href="https://react.dev/learn"&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up a React Environment
&lt;/h2&gt;

&lt;p&gt;If you have npx and Node.js installed, you can create a React application by using &lt;code&gt;create-react-app&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Run this command to create a React application named &lt;code&gt;my-react-app&lt;/code&gt;:&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-react-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;create-react-app&lt;/code&gt; will set up everything you need to run a React application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Run the React Application
&lt;/h3&gt;

&lt;p&gt;Now you are ready to run your first real React application!&lt;/p&gt;

&lt;p&gt;Run this command to move to the &lt;code&gt;my-react-app&lt;/code&gt; directory:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Run this command to run the React application &lt;code&gt;my-react-app&lt;/code&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 start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A new browser window will pop up with your newly created React App! If not, open your browser and type &lt;code&gt;localhost:3000&lt;/code&gt; in the address bar.&lt;/p&gt;

&lt;h2&gt;
  
  
  State and Props
&lt;/h2&gt;

&lt;p&gt;State and props are two fundamental concepts in React for managing component-specific data.&lt;/p&gt;

&lt;h3&gt;
  
  
  State
&lt;/h3&gt;

&lt;p&gt;State is a way for a component to maintain and manage its own data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Counter extends React.Component {
  constructor(props) {
    super(props);
    this.state = { count: 0 };
  }

  render() {
    return (
      &amp;lt;div&amp;gt;
        &amp;lt;p&amp;gt;Count: {this.state.count}&amp;lt;/p&amp;gt;
        &amp;lt;button onClick={() =&amp;gt; this.setState({ count: this.state.count + 1 })}&amp;gt;
          Increment
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;Counter&lt;/code&gt; component maintains its count in the state.&lt;/p&gt;

&lt;h3&gt;
  
  
  Props
&lt;/h3&gt;

&lt;p&gt;Props are inputs that a React component can receive.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Greet(props) {
  return &amp;lt;p&amp;gt;Hello, {props.name}!&amp;lt;/p&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the &lt;code&gt;Greet&lt;/code&gt; component receives a name prop.&lt;/p&gt;

&lt;h3&gt;
  
  
  Functional Components
&lt;/h3&gt;

&lt;p&gt;Functional components are simple JavaScript functions that take in props and return React elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Welcome(props) {
  return &amp;lt;h1&amp;gt;Hello, {props.name}&amp;lt;/h1&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Class Components
&lt;/h3&gt;

&lt;p&gt;Class components are ES6 classes that extend from &lt;code&gt;React.Component&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class WelcomeClass extends React.Component {
  render() {
    return &amp;lt;h1&amp;gt;Hello, {this.props.name}&amp;lt;/h1&amp;gt;;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above examples, both components display a greeting based on the provided &lt;code&gt;name&lt;/code&gt; prop.&lt;/p&gt;

&lt;h2&gt;
  
  
  React Hooks
&lt;/h2&gt;

&lt;p&gt;React Hooks were introduced to allow functional components to use state and lifecycle features.&lt;/p&gt;

&lt;h3&gt;
  
  
  useState Hook
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The React &lt;code&gt;useState&lt;/code&gt; Hook allows us to track state in a function component.&lt;/li&gt;
&lt;li&gt;State generally refers to data or properties that need to be tracking in an application.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Initialize useState
&lt;/h4&gt;

&lt;p&gt;We initialize our state by calling &lt;code&gt;useState&lt;/code&gt; in our function component.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useState&lt;/code&gt; accepts an initial state and returns two values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The current state.&lt;/li&gt;
&lt;li&gt;A function that updates the state.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Initialize state at the top of the function component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";

function FavoriteColor() {
  const [color, setColor] = useState("");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that again, we are destructuring the returned values from &lt;code&gt;useState&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first value, &lt;code&gt;color&lt;/code&gt;, is our current state.&lt;/li&gt;
&lt;li&gt;The second value, &lt;code&gt;setColor&lt;/code&gt;, is the function that is used to update our state.&lt;/li&gt;
&lt;li&gt;Lastly, we set the initial state to an empty string: &lt;code&gt;useState("")&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from "react";

function Counter() {
  const [count, setCount] = useState(0);

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;Count: {count}&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setCount(count + 1)}&amp;gt;Increment&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the Counter component uses the useState hook to manage the count state.&lt;/p&gt;

&lt;p&gt;Let's take an example of how to update a state by &lt;code&gt;useState&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";
import ReactDOM from "react-dom/client";

function FavoriteColor() {
  const [color, setColor] = useState("red");

  return (
    &amp;lt;&amp;gt;
      &amp;lt;h1&amp;gt;My favorite color is {color}!&amp;lt;/h1&amp;gt;
      &amp;lt;button
        type="button"
        onClick={() =&amp;gt; setColor("blue")}
      &amp;gt;Blue&amp;lt;/button&amp;gt;
    &amp;lt;/&amp;gt;
  )
}

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(&amp;lt;FavoriteColor /&amp;gt;);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  useEffect Hook
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;useEffect&lt;/code&gt; Hook allows you to perform side effects in your components.&lt;/li&gt;
&lt;li&gt;Some examples of side effects are: fetching data, directly updating the DOM, and timers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;useEffect&lt;/code&gt; accepts two arguments. The second argument is optional.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useEffect(&amp;lt;function&amp;gt;, &amp;lt;dependency&amp;gt;)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's take an example and understand 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, useEffect } from "react";

function DataFetcher() {
  const [data, setData] = useState(null);

  useEffect(() =&amp;gt; {
    const fetchData = async () =&amp;gt; {
      try {
        const result = await new Promise((resolve) =&amp;gt;
          setTimeout(() =&amp;gt; resolve("Fetched data"), 1000)
        );
        setData(result);
      } catch (error) {
        console.error(error);
      }
    };

    fetchData();
  }, []); // Empty dependency array means it runs once after the initial render

  return &amp;lt;p&amp;gt;Data: {data}&amp;lt;/p&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Import Statements:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;React&lt;/code&gt; is imported as it's required for JSX.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useEffect&lt;/code&gt; are imported from React. These are Hooks used for managing state and performing side effects in functional components.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Functional Component &lt;code&gt;DataFetcher&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;DataFetcher&lt;/code&gt; is a functional component that fetches and displays data.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;const [data, setData] = useState(null);&lt;/code&gt;: This line uses the &lt;code&gt;useState&lt;/code&gt; Hook to create a state variable &lt;code&gt;data&lt;/code&gt; initialized to &lt;code&gt;null&lt;/code&gt;, and a function &lt;code&gt;setData&lt;/code&gt; to update this state.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;useEffect&lt;/code&gt; Hook:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;useEffect&lt;/code&gt; is used to perform side effects in a functional component. It runs after the initial render and can be used for data fetching, subscriptions, or manually changing the DOM.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;fetchData&lt;/code&gt; Function:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;fetchData&lt;/code&gt; is an asynchronous function that simulates data fetching after a delay of 1000 milliseconds using &lt;code&gt;setTimeout&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;try-catch&lt;/code&gt; Block:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;try&lt;/code&gt; block attempts to fetch data and sets it using &lt;code&gt;setData&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If an error occurs during the data fetching process, it's caught in the &lt;code&gt;catch&lt;/code&gt; block, and an error message is logged to the console.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;fetchData&lt;/code&gt; Invocation in &lt;code&gt;useEffect&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;fetchData&lt;/code&gt; function is invoked inside the &lt;code&gt;useEffect&lt;/code&gt; Hook.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Dependency Array:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The dependency array (&lt;code&gt;[]&lt;/code&gt;) is empty, meaning the &lt;code&gt;useEffect&lt;/code&gt; runs once after the initial render. If there were dependencies listed, the effect would run whenever those dependencies change.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Return Statement:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The component returns JSX that displays the fetched data inside a &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; element.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In summary, this component fetches data using the &lt;code&gt;useEffect&lt;/code&gt; Hook, updates the state with the fetched data, and renders the data in the component. The empty dependency array ensures that the effect runs only once after the initial render.&lt;/p&gt;

&lt;h2&gt;
  
  
  React Router Dom
&lt;/h2&gt;

&lt;p&gt;React Router Dom is a library for handling navigation in React applications.&lt;/p&gt;

&lt;p&gt;To add React Router in your application, run this in the terminal from the root directory of the application:&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 -D react-router-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's take another example and understand Router-Dom.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { BrowserRouter as Router, Route, Link, useParams } from "react-router-dom";

function UserProfile() {
  let { username } = useParams();
  return &amp;lt;h2&amp;gt;User Profile: {username}&amp;lt;/h2&amp;gt;;
}

function App() {
  return (
    &amp;lt;Router&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;nav&amp;gt;
          &amp;lt;ul&amp;gt;
            &amp;lt;li&amp;gt;
              &amp;lt;Link to="/"&amp;gt;Home&amp;lt;/Link&amp;gt;
            &amp;lt;/li&amp;gt;
            &amp;lt;li&amp;gt;
              &amp;lt;Link to="/user/john"&amp;gt;User John&amp;lt;/Link&amp;gt;
            &amp;lt;/li&amp;gt;
          &amp;lt;/ul&amp;gt;
        &amp;lt;/nav&amp;gt;

        &amp;lt;Route path="/user/:username" component={UserProfile} /&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/Router&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Import Statements:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The code imports components from the &lt;code&gt;react-router-dom&lt;/code&gt; library for setting up routing in a React application.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;BrowserRouter as Router&lt;/code&gt;, &lt;code&gt;Route&lt;/code&gt;, &lt;code&gt;Link&lt;/code&gt;, and &lt;code&gt;useParams&lt;/code&gt; are imported.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Functional Component &lt;code&gt;UserProfile&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;UserProfile&lt;/code&gt; is a functional component that extracts the &lt;code&gt;username&lt;/code&gt; parameter from the URL using the &lt;code&gt;useParams&lt;/code&gt; hook.&lt;/li&gt;
&lt;li&gt;It returns an &lt;code&gt;&amp;lt;h2&amp;gt;&lt;/code&gt; element displaying the user profile based on the extracted &lt;code&gt;username&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Functional Component &lt;code&gt;App&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;App&lt;/code&gt; is a functional component representing the main structure of the application.&lt;/li&gt;
&lt;li&gt;It uses the &lt;code&gt;Router&lt;/code&gt; component to define the router context for the application.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Navigation Setup:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;nav&lt;/code&gt; element contains an unordered list (&lt;code&gt;ul&lt;/code&gt;) with list items (&lt;code&gt;li&lt;/code&gt;) representing navigation links.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Link&lt;/code&gt; components are used for creating navigation links. The links point to different routes, such as the home route ("/") and a user route ("/user/john").&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Route Definition:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;Route&lt;/code&gt; component is used to define a route for the user profile. It specifies that when the URL matches the pattern "/user/:username," the &lt;code&gt;UserProfile&lt;/code&gt; component should be rendered.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Router Context:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The entire structure is wrapped in the &lt;code&gt;Router&lt;/code&gt; component to establish the router context for the application.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In summary, this code sets up basic navigation using &lt;code&gt;react-router-dom&lt;/code&gt;. The &lt;code&gt;App&lt;/code&gt; component defines routes, and the &lt;code&gt;UserProfile&lt;/code&gt; component dynamically displays user profiles based on the username parameter extracted from the URL.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  Getting Started with the Project: Project Installation
&lt;/h2&gt;
&lt;/blockquote&gt;

&lt;p&gt;After the completion of the Project, your minimized project structure should be looking like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mCOgRTWj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hxf6lzw4wg5offvk9yul.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mCOgRTWj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hxf6lzw4wg5offvk9yul.png" alt="Image description" width="615" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  React Custom Package
&lt;/h2&gt;

&lt;p&gt;We've chosen to create our own special toolkit (SDK) for handling IPFS uploads in our project. This decision is intentional – we're starting to use it right from the beginning. This approach makes things smoother as we progress, ensuring that the toolkit is perfectly suited to our needs for implementing the desired features in later stages of development.&lt;/p&gt;

&lt;p&gt;You can find more about &lt;strong&gt;ipfs-http-client&lt;/strong&gt; &lt;a href="https://www.npmjs.com/package/ipfs-http-client"&gt;Here&lt;/a&gt;.&lt;br&gt;
You can find more about &lt;strong&gt;Helia&lt;/strong&gt; &lt;a href="https://helia.io/"&gt;Here&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  thirdweb React SDK
&lt;/h3&gt;

&lt;p&gt;Ultimate collection of React hooks for your web3 apps.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can find more about this package &lt;a href="https://www.npmjs.com/package/@thirdweb-dev/react"&gt;Here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Let’s start the project by choosing the right directory where you want to create your project and start with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx thirdweb create --app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Then choose create-react-app&lt;/li&gt;
&lt;li&gt;Then choose JavaScript&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>frontend</category>
      <category>javascript</category>
      <category>react</category>
      <category>ipfs</category>
    </item>
  </channel>
</rss>
