<?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: kumarshivam1998</title>
    <description>The latest articles on DEV Community by kumarshivam1998 (@kumarshivam1998).</description>
    <link>https://dev.to/kumarshivam1998</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%2F1117159%2Fda513d26-8de9-4d0c-b233-db913084b320.jpeg</url>
      <title>DEV Community: kumarshivam1998</title>
      <link>https://dev.to/kumarshivam1998</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kumarshivam1998"/>
    <language>en</language>
    <item>
      <title>Understanding How CORS Works in Web Browsers</title>
      <dc:creator>kumarshivam1998</dc:creator>
      <pubDate>Tue, 17 Sep 2024 05:37:48 +0000</pubDate>
      <link>https://dev.to/kumarshivam1998/understanding-how-cors-works-in-web-browsers-37a0</link>
      <guid>https://dev.to/kumarshivam1998/understanding-how-cors-works-in-web-browsers-37a0</guid>
      <description>&lt;p&gt;Cross-Origin Resource Sharing (CORS) is a critical security feature in web browsers that governs how web applications can request resources (such as data, images, or scripts) from a different domain than the one that served the initial web page. It is primarily designed to protect users from malicious sites attempting to access sensitive information on other websites. This blog will explain how CORS works and why it is crucial for web development.&lt;br&gt;
What is CORS?&lt;br&gt;
In simple terms, CORS is a browser mechanism that controls which resources a web page can request from different domains. By default, browsers implement the Same-Origin Policy (SOP), which restricts web pages from making requests to a domain other than the one from which the page was loaded. This policy is a fundamental security feature that prevents potentially harmful interactions between websites.&lt;/p&gt;

&lt;p&gt;However, there are many cases where legitimate cross-origin requests are necessary—for example, when a web application needs to fetch data from an API hosted on a different server. CORS enables such requests in a secure manner by allowing servers to specify which domains are allowed to access their resources.&lt;/p&gt;

&lt;p&gt;How Does CORS Work?&lt;br&gt;
CORS works by adding HTTP headers to the responses from a server, indicating whether or not a cross-origin request is permitted. Here’s a step-by-step breakdown of how CORS operates:&lt;/p&gt;

&lt;p&gt;The Client Makes a Request&lt;br&gt;
When a web page tries to make a request (e.g., via XMLHttpRequest, fetch, or script inclusion) to a different origin (defined by domain, protocol, and port), the browser checks whether the request violates the same-origin policy.&lt;/p&gt;

&lt;p&gt;CORS Preflight Request (For Complex Requests)&lt;br&gt;
Some requests, particularly those with methods like PUT, DELETE, or with custom headers, are considered "complex." Before sending the actual request, the browser sends an OPTIONS request, known as a preflight request. This preflight request asks the server whether it allows the actual request and verifies the allowed HTTP methods, headers, and origins.&lt;/p&gt;

&lt;p&gt;Server Responds with CORS Headers&lt;br&gt;
The server receiving the preflight or actual request sends back a response with specific headers indicating whether the request is allowed. Key headers include:&lt;/p&gt;

&lt;p&gt;Access-Control-Allow-Origin: This header specifies which domains are permitted to access the resource. If this header includes the origin of the request, the browser allows the response. For example, the server might respond with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Access-Control-Allow-Origin: https://example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Access-Control-Allow-Methods: This header specifies which HTTP methods (GET, POST, PUT, etc.) the server allows for cross-origin requests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Access-Control-Allow-Methods: GET, POST
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Access-Control-Allow-Headers: This specifies which custom headers can be included in the actual request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Access-Control-Allow-Headers: Content-Type, Authorization
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Access-Control-Allow-Credentials: If the server allows credentials (cookies, HTTP authentication), this header will be included and set to true.&lt;/p&gt;

&lt;p&gt;The Browser Decides&lt;br&gt;
After receiving the server's response, the browser evaluates the headers. If the server grants permission through the appropriate CORS headers, the browser allows the cross-origin request and processes the response. If not, the browser blocks the request and the web page is unable to access the resource.&lt;/p&gt;

&lt;p&gt;Example of a Simple CORS Request&lt;br&gt;
Consider a scenario where a web page hosted on &lt;a href="https://example.com" rel="noopener noreferrer"&gt;https://example.com&lt;/a&gt; attempts to make a GET request to an API hosted at &lt;a href="https://api.example.com/data" rel="noopener noreferrer"&gt;https://api.example.com/data&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;fetch('https://api.example.com/data')
  .then(response =&amp;gt; response.json())
  .then(data =&amp;gt; console.log(data))
  .catch(error =&amp;gt; console.error('Error:', error));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, the browser sends the request to &lt;a href="https://api.example.com" rel="noopener noreferrer"&gt;https://api.example.com&lt;/a&gt;. If the API server is configured to allow requests from &lt;a href="https://example.com" rel="noopener noreferrer"&gt;https://example.com&lt;/a&gt;, it will respond with the header:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Access-Control-Allow-Origin: https://example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the header is absent or incorrect, the browser will block the response due to CORS policy.&lt;/p&gt;

&lt;p&gt;CORS Preflight Example&lt;br&gt;
For more complex requests, the browser initiates a preflight request to check whether the cross-origin request is allowed. Here's an example of a PUT request that triggers a preflight:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch('https://api.example.com/update', {
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ key: 'value' })
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The browser sends an OPTIONS request 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;OPTIONS /update HTTP/1.1
Origin: https://example.com
Access-Control-Request-Method: PUT
Access-Control-Request-Headers: Content-Type
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server should respond with headers indicating whether this request is allowed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Access-Control-Allow-Origin: https://example.com
Access-Control-Allow-Methods: PUT
Access-Control-Allow-Headers: Content-Type
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If these headers are present and valid, the browser will proceed with the actual PUT request.&lt;/p&gt;

&lt;p&gt;Importance of CORS&lt;br&gt;
CORS is a security feature that provides a fine-grained mechanism for web servers to control access to their resources. Without CORS, malicious websites could easily fetch sensitive data from other domains without user consent, leading to security vulnerabilities like Cross-Site Request Forgery (CSRF).&lt;/p&gt;

&lt;p&gt;Conclusion&lt;br&gt;
Understanding CORS is essential for web developers working with APIs and third-party resources. By configuring proper CORS policies on servers, developers can ensure that their applications remain secure while still enabling legitimate cross-origin interactions.&lt;/p&gt;

&lt;p&gt;If you are developing a web app and encountering CORS errors, it's essential to check the server's configuration and ensure the necessary headers are being sent in the response.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>MongoDB Beginner's Guide: A Step-by-Step Introduction</title>
      <dc:creator>kumarshivam1998</dc:creator>
      <pubDate>Mon, 05 Aug 2024 07:19:11 +0000</pubDate>
      <link>https://dev.to/kumarshivam1998/mongodb-beginners-guide-a-step-by-step-introduction-4cg3</link>
      <guid>https://dev.to/kumarshivam1998/mongodb-beginners-guide-a-step-by-step-introduction-4cg3</guid>
      <description>&lt;p&gt;MongoDB is a popular NoSQL database that is known for its flexibility, scalability, and ease of use. Unlike traditional relational databases, MongoDB stores data in a JSON-like format called BSON, which allows for a more dynamic and flexible schema. This makes it an excellent choice for applications that require large volumes of data or need to evolve quickly.&lt;/p&gt;

&lt;p&gt;In this guide, we’ll walk through the basics of MongoDB to help you get started.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is MongoDB?
&lt;/h3&gt;

&lt;p&gt;MongoDB is a document-oriented database that provides high performance, high availability, and easy scalability. It is open-source and developed by MongoDB Inc. Its key features include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Document Storage&lt;/strong&gt;: Data is stored in BSON format, a binary representation of JSON documents.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexible Schema&lt;/strong&gt;: Allows for the storage of complex data structures.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: Easily scales horizontally with sharding.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Indexing&lt;/strong&gt;: Supports a wide range of indexes and search queries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Aggregation&lt;/strong&gt;: Provides powerful ways to aggregate and analyze data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Setting Up MongoDB
&lt;/h3&gt;

&lt;p&gt;To get started with MongoDB, you need to install it on your system. Follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Download MongoDB&lt;/strong&gt;: Visit the &lt;a href="https://www.mongodb.com/try/download/community" rel="noopener noreferrer"&gt;official MongoDB website&lt;/a&gt; to download the Community Server edition suitable for your operating system.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install MongoDB&lt;/strong&gt;: Follow the installation instructions for your specific platform. MongoDB provides detailed guides for Windows, macOS, and Linux.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Run MongoDB&lt;/strong&gt;: Once installed, you can start the MongoDB server (mongod) using the terminal or command prompt. By default, MongoDB listens on port 27017.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Access MongoDB&lt;/strong&gt;: Use the MongoDB shell (mongo) to interact with your database. You can also use graphical interfaces like MongoDB Compass for easier management.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Basic MongoDB Operations
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Creating a Database
&lt;/h4&gt;

&lt;p&gt;In MongoDB, databases are created on the fly. Simply switch to a new database, and it will be created once you insert data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;use mydatabase
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Creating a Collection
&lt;/h4&gt;

&lt;p&gt;Collections in MongoDB are akin to tables in relational databases. They hold documents.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;db.createCollection&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"mycollection"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Inserting Documents
&lt;/h4&gt;

&lt;p&gt;To add data to your collection, you can use the &lt;code&gt;insertOne&lt;/code&gt; or &lt;code&gt;insertMany&lt;/code&gt; methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;db.mycollection.insertOne&lt;span class="o"&gt;({&lt;/span&gt; name: &lt;span class="s2"&gt;"John Doe"&lt;/span&gt;, age: 29, city: &lt;span class="s2"&gt;"New York"&lt;/span&gt; &lt;span class="o"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;db.mycollection.insertMany&lt;span class="o"&gt;([&lt;/span&gt;
  &lt;span class="o"&gt;{&lt;/span&gt; name: &lt;span class="s2"&gt;"Jane Smith"&lt;/span&gt;, age: 34, city: &lt;span class="s2"&gt;"San Francisco"&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;,
  &lt;span class="o"&gt;{&lt;/span&gt; name: &lt;span class="s2"&gt;"Peter Parker"&lt;/span&gt;, age: 22, city: &lt;span class="s2"&gt;"Queens"&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Querying Data
&lt;/h4&gt;

&lt;p&gt;MongoDB provides powerful query capabilities to retrieve data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;db.mycollection.find&lt;span class="o"&gt;({&lt;/span&gt; city: &lt;span class="s2"&gt;"New York"&lt;/span&gt; &lt;span class="o"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will return all documents where the city is New York.&lt;/p&gt;

&lt;h4&gt;
  
  
  Updating Documents
&lt;/h4&gt;

&lt;p&gt;To update existing documents, use the &lt;code&gt;updateOne&lt;/code&gt; or &lt;code&gt;updateMany&lt;/code&gt; methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;db.mycollection.updateOne&lt;span class="o"&gt;({&lt;/span&gt; name: &lt;span class="s2"&gt;"John Doe"&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;, &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$set&lt;/span&gt;: &lt;span class="o"&gt;{&lt;/span&gt; age: 30 &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="o"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Deleting Documents
&lt;/h4&gt;

&lt;p&gt;To remove documents, you can use the &lt;code&gt;deleteOne&lt;/code&gt; or &lt;code&gt;deleteMany&lt;/code&gt; methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;db.mycollection.deleteOne&lt;span class="o"&gt;({&lt;/span&gt; name: &lt;span class="s2"&gt;"Jane Smith"&lt;/span&gt; &lt;span class="o"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;MongoDB is a versatile and powerful database that is easy to get started with, especially for projects that require rapid iteration and scalability. This guide covered the basics, but there is much more to explore, including advanced querying, indexing, and aggregation frameworks. As you continue your journey with MongoDB, you’ll discover its full potential and how it can effectively meet your application needs.&lt;/p&gt;

&lt;p&gt;Whether you are building a web app, mobile app, or any other type of application, MongoDB can provide the robust database solution you need. Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>mongodb</category>
      <category>programming</category>
    </item>
    <item>
      <title>Mastering Git: An In-Depth Guide</title>
      <dc:creator>kumarshivam1998</dc:creator>
      <pubDate>Fri, 26 Jul 2024 07:30:28 +0000</pubDate>
      <link>https://dev.to/kumarshivam1998/mastering-git-an-in-depth-guide-53lp</link>
      <guid>https://dev.to/kumarshivam1998/mastering-git-an-in-depth-guide-53lp</guid>
      <description>&lt;p&gt;Git is a powerful version control system that has become an essential tool for developers and teams worldwide. Whether you're working on a solo project or collaborating with a large team, Git helps manage changes, track history, and facilitate seamless collaboration. In this guide, we'll dive deep into Git, covering everything from the basics to advanced techniques, to help you master this indispensable tool.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding Git: The Basics&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What is Git?&lt;br&gt;
Git is a distributed version control system created by Linus Torvalds in 2005. It allows multiple developers to work on a project simultaneously, managing changes efficiently and ensuring that code can be merged and shared without conflicts.&lt;/p&gt;

&lt;p&gt;Key Concepts&lt;br&gt;
Repository: A Git repository is a directory containing your project files and the .git folder, which stores all the metadata and version history.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Commit: A commit is a snapshot of your repository at a specific point in time. It records changes to files and allows you to revert to previous states if needed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Branch: Branches allow you to develop features or fixes in isolation from the main codebase. The main (or master) branch is typically the default, but you can create and merge other branches as needed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Merge: Merging combines changes from different branches into a single branch, allowing you to integrate new features or fixes into the main codebase.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Clone: Cloning creates a copy of a remote repository on your local machine, allowing you to work on it independently.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Setting Up Git&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Installation&lt;br&gt;
To get started with Git, you need to install it on your machine. You can download the latest version from git-scm.com, which provides installers for Windows, macOS, and Linux.&lt;/p&gt;

&lt;p&gt;Configuration&lt;br&gt;
After installation, configure Git with your username and email address:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

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

&lt;/div&gt;



&lt;p&gt;These details will be used in your commits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic Git Commands&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Initializing a Repository&lt;br&gt;
To create a new Git repository, navigate to your project directory and run:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;This command creates a new .git folder, setting up a fresh repository.&lt;/p&gt;

&lt;p&gt;Cloning a Repository&lt;br&gt;
To clone an existing repository, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone &amp;lt;repository-url&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;This command downloads the repository and its history to your local machine.&lt;/p&gt;

&lt;p&gt;Staging and Committing Changes&lt;br&gt;
To stage changes, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add &amp;lt;file-name&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Or, to stage all changes:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;To commit staged changes, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m "Your commit message"

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

&lt;/div&gt;



&lt;p&gt;Checking Status&lt;br&gt;
To see the current status of your repository, use:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;This command shows which files are staged, modified, or untracked.&lt;/p&gt;

&lt;p&gt;Viewing Commit History&lt;br&gt;
To view the commit history, run:&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;Branching and Merging&lt;br&gt;
Creating a Branch&lt;br&gt;
To create a new branch, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch &amp;lt;branch-name&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Switching Branches&lt;br&gt;
To switch to a different branch, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout &amp;lt;branch-name&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Merging Branches&lt;br&gt;
To merge changes from one branch into another, first switch to the target branch and then run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git merge &amp;lt;branch-name&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Resolving Conflicts&lt;br&gt;
Conflicts may occur during merging if changes overlap. Git will highlight conflicting files, and you'll need to manually resolve them before committing the merge.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advanced Git Techniques&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rebasing&lt;br&gt;
Rebasing is an alternative to merging that allows you to integrate changes without creating a new commit history. It rewrites the commit history, making it linear and cleaner.&lt;/p&gt;

&lt;p&gt;To rebase a branch, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rebase &amp;lt;base-branch&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Stashing&lt;br&gt;
If you need to switch branches but have uncommitted changes, you can stash them temporarily:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;To apply stashed changes, run:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;Undoing Changes&lt;br&gt;
To undo changes in a file, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout -- &amp;lt;file-name&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;To reset the entire working directory to the last commit, use:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Best Practices&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Commit Often: Make small, frequent commits with clear messages to keep your history organized and understandable.&lt;/p&gt;

&lt;p&gt;Use Branches: Create branches for new features or bug fixes to keep the main branch stable.&lt;/p&gt;

&lt;p&gt;Regularly Pull Updates: Regularly fetch and merge changes from the remote repository to stay up to date.&lt;/p&gt;

&lt;p&gt;Review Changes: Before committing, review your changes using git diff to ensure you're only including what you intend to.&lt;/p&gt;

&lt;p&gt;Write Descriptive Commit Messages: Clearly describe what each commit does to make the history easier to understand.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Mastering Git takes time and practice, but understanding its core concepts and commands is crucial for efficient version control. By following this guide and continuously exploring advanced techniques, you'll become proficient in managing your projects with Git. Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Understanding React Hooks: A Beginner's Guide</title>
      <dc:creator>kumarshivam1998</dc:creator>
      <pubDate>Wed, 24 Jul 2024 07:52:37 +0000</pubDate>
      <link>https://dev.to/kumarshivam1998/understanding-react-hooks-a-beginners-guide-3ibm</link>
      <guid>https://dev.to/kumarshivam1998/understanding-react-hooks-a-beginners-guide-3ibm</guid>
      <description>&lt;p&gt;React Hooks are a powerful feature in React that allow you to use state and other React features without writing a class. Introduced in React 16.8, hooks make it easier to manage state and side effects in your functional components. In this blog post, we'll explore the basics of React Hooks and how you can use them in your projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Hooks?
&lt;/h2&gt;

&lt;p&gt;Before hooks, if you wanted to use state in a React component, you had to use a class component. This often led to more complex and less readable code. Hooks solve this problem by allowing you to use state and other features in functional components, which are typically simpler and easier to work with.&lt;/p&gt;

&lt;p&gt;The Most Common Hooks&lt;/p&gt;

&lt;p&gt;There are several hooks available in React, but we'll focus on the two most commonly used ones: useState and useEffect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useState&lt;/strong&gt;&lt;br&gt;
The useState hook lets you add state to your functional components. Here's how it works:&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 } from 'react';

function Counter() {
  // Declare a new state variable called "count"
  const [count, setCount] = useState(0);

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;You clicked {count} times&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setCount(count + 1)}&amp;gt;
        Click me
      &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, we import useState from React. We then call useState(0) to initialize our state variable count with a value of 0. useState returns an array with two elements: the current state (count) and a function to update it (setCount). We use these in our component to display and update the count value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useEffect&lt;/strong&gt;&lt;br&gt;
The useEffect hook lets you perform side effects in your components. It’s similar to lifecycle methods in class components like componentDidMount, componentDidUpdate, and componentWillUnmount.&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 Example() {
  const [count, setCount] = useState(0);

  // Similar to componentDidMount and componentDidUpdate:
  useEffect(() =&amp;gt; {
    // Update the document title using the browser API
    document.title = `You clicked ${count} times`;
  }, [count]); // Only re-run the effect if count changes

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;You clicked {count} times&amp;lt;/p&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setCount(count + 1)}&amp;gt;
        Click me
      &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, we use useEffect to update the document title whenever the count changes. The function inside useEffect runs after every render by default. However, by providing [count] as the second argument, it only runs when count changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rules of Hooks
&lt;/h2&gt;

&lt;p&gt;When using hooks, there are a few rules you need to follow:&lt;/p&gt;

&lt;p&gt;1- Only Call Hooks at the Top Level: Don’t call hooks inside loops, conditions, or nested functions. Always use them at the top level of your component so that React can preserve the state correctly.&lt;/p&gt;

&lt;p&gt;2- Only Call Hooks from React Functions: You can call hooks from React functional components or custom hooks, but not from regular JavaScript functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Custom Hooks
&lt;/h2&gt;

&lt;p&gt;Custom hooks allow you to extract and reuse stateful logic across components. They’re JavaScript functions whose names start with "use" and can call other hooks inside them.&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';

// Custom hook to fetch data
function useFetchData(url) {
  const [data, setData] = useState(null);

  useEffect(() =&amp;gt; {
    async function fetchData() {
      const response = await fetch(url);
      const result = await response.json();
      setData(result);
    }

    fetchData();
  }, [url]);

  return data;
}

function DataDisplay() {
  const data = useFetchData('https://api.example.com/data');

  if (!data) return &amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;;

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Data&amp;lt;/h1&amp;gt;
      &amp;lt;pre&amp;gt;{JSON.stringify(data, null, 2)}&amp;lt;/pre&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;In this example, useFetchData is a custom hook that fetches data from a given URL. It uses useState to manage the data and useEffect to perform the fetch operation.&lt;/p&gt;

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

&lt;p&gt;React Hooks are a game-changer for building React applications. They make it easier to write clean and maintainable code by enabling state and side effects in functional components. By understanding useState, useEffect, and custom hooks, you can unlock the full potential of hooks in your React projects.&lt;/p&gt;

&lt;p&gt;Feel free to experiment with hooks in your projects and explore other hooks like useContext, useReducer, and more to enhance your applications even further!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
