<?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: Shubhankar Valimbe</title>
    <description>The latest articles on Forem by Shubhankar Valimbe (@shubhankarval).</description>
    <link>https://forem.com/shubhankarval</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%2F1156627%2F082d739e-89ea-42c4-afa9-5419a40c87fb.jpeg</url>
      <title>Forem: Shubhankar Valimbe</title>
      <link>https://forem.com/shubhankarval</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/shubhankarval"/>
    <language>en</language>
    <item>
      <title>Introducing nextjs-starter-pack: my first npm package</title>
      <dc:creator>Shubhankar Valimbe</dc:creator>
      <pubDate>Sun, 20 Jul 2025 00:30:16 +0000</pubDate>
      <link>https://forem.com/shubhankarval/introducing-nextjs-starter-pack-f1o</link>
      <guid>https://forem.com/shubhankarval/introducing-nextjs-starter-pack-f1o</guid>
      <description>&lt;p&gt;I have gotten so tired of spending 2-3 hours setting up the same stack for every new Next.js project. Database, auth, state management, forms - it's always the same dance. To simplify that, I created &lt;a href="https://github.com/shubhankarval/nextjs-starter-pack" rel="noopener noreferrer"&gt;&lt;code&gt;nextjs-starter-pack&lt;/code&gt;&lt;/a&gt; — a one-command CLI to generate a fully configured, modern Next.js 15 apps with customizable integrations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why I built this
&lt;/h3&gt;

&lt;p&gt;Every developer has that folder of "reference projects" they copy configs from. I realized I was basically rebuilding the same foundation over and over, just with slight variations depending on the project needs.&lt;/p&gt;

&lt;p&gt;The breaking point was starting my fourth SaaS project and realizing I was about to spend another afternoon wiring up Clerk auth with Prisma... again.&lt;/p&gt;

&lt;p&gt;Instead of copying code, why not generate it?&lt;/p&gt;




&lt;h3&gt;
  
  
  Getting Started
&lt;/h3&gt;

&lt;p&gt;Try it 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 nextjs-starter-pack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or explore the full range of options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx nextjs-starter-pack --help
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  What You Get
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Foundation&lt;/strong&gt;: Next.js 15 + React 19 + TypeScript + Tailwind + Shadcn/ui&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Database&lt;/strong&gt;: Prisma or Drizzle&lt;br&gt;
&lt;strong&gt;Auth&lt;/strong&gt;: Auth.js or Clerk&lt;br&gt;
&lt;strong&gt;State&lt;/strong&gt;: Zustand or Jotai&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Plus&lt;/strong&gt;: TanStack Query • React Hook Form + Zod • Dark mode&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs859ovu5lau1jaqbc9m5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs859ovu5lau1jaqbc9m5.png" alt="nextjs-starter-pack CLI" width="775" height="359"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Try It Today
&lt;/h3&gt;

&lt;p&gt;If you're tired of the setup ceremony that comes with every new Next.js project, give &lt;code&gt;nextjs-starter-pack&lt;/code&gt; a try. It might just save you an hour on your next project.&lt;/p&gt;

&lt;p&gt;Links:&lt;br&gt;
&lt;a href="https://github.com/shubhankarval/nextjs-starter-pack" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.npmjs.com/package/nextjs-starter-pack" rel="noopener noreferrer"&gt;NPM Package&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your feedback or feature requests. Feel free to open an issue on GitHub or reach out directly.&lt;/p&gt;

&lt;p&gt;I'm actively working on new integrations (Stripe, i18n, CI/CD workflows, analytics, PWA, etc.) to make this the go-to for creating Next.js apps, and if any open sourcers are interested in helping build this, feel free to reach out on &lt;a href="https://www.reddit.com/user/General_Mix9068/" rel="noopener noreferrer"&gt;Reddit&lt;/a&gt;. &lt;/p&gt;




&lt;p&gt;&lt;em&gt;Stop setting up. Start building.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>webdev</category>
      <category>tailwindcss</category>
    </item>
    <item>
      <title>GitHub 102: Branching Strategies, Pull Requests, and More</title>
      <dc:creator>Shubhankar Valimbe</dc:creator>
      <pubDate>Mon, 25 Sep 2023 21:16:50 +0000</pubDate>
      <link>https://forem.com/shubhankarval/github-102-branching-strategies-pull-requests-and-more-11hk</link>
      <guid>https://forem.com/shubhankarval/github-102-branching-strategies-pull-requests-and-more-11hk</guid>
      <description>&lt;p&gt;Hello beautiful people! &lt;/p&gt;

&lt;p&gt;Collaborative software development with Git and GitHub requires more than just the basics. In this guide, we'll explore advanced topics and best practices that will help you become a Git and GitHub collaboration pro.&lt;/p&gt;

&lt;h2&gt;
  
  
  Branching Strategies
&lt;/h2&gt;

&lt;p&gt;Branching is a fundamental concept in Git, and different branching strategies can make or break a project's development process. Here are some common branching strategies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Feature Branching&lt;/strong&gt;: Create a branch for each new feature or enhancement. This keeps the main branch (usually &lt;code&gt;main&lt;/code&gt; or &lt;code&gt;master&lt;/code&gt;) stable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Release Branching&lt;/strong&gt;: Use release branches to prepare for a new version. Any bug fixes or last-minute changes go into this branch before a release.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hotfix Branching&lt;/strong&gt;: For critical fixes in production, create a hotfix branch based on the &lt;code&gt;main&lt;/code&gt; branch. Once tested, merge it back into both &lt;code&gt;main&lt;/code&gt; and the active development branch.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Pull Requests and Code Review
&lt;/h2&gt;

&lt;p&gt;Pull requests are the heart of collaboration on GitHub. They enable you to propose changes, get feedback, and ensure code quality. Here's how it works:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a Pull Request (PR)&lt;/strong&gt;: When you're ready to merge your branch, open a PR. Describe the changes and add reviewers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code Review&lt;/strong&gt;: Reviewers provide feedback, ask questions, and suggest improvements. Address these comments before merging.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Continuous Integration (CI)&lt;/strong&gt;: Ensure your code passes automated tests configured in your repository. Many CI tools integrate with GitHub.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Merge and Close&lt;/strong&gt;: Once the PR is approved and CI passes, merge the changes. Don't forget to delete your branch if it's no longer needed.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Collaborating with Others
&lt;/h2&gt;

&lt;p&gt;Collaboration is more than just code. Effective teamwork includes communication, shared goals, and clarity. Here are some tips:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Communication&lt;/strong&gt;: Use GitHub's issue tracker, discussion boards, and comments in PRs for clear communication.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Shared Goals&lt;/strong&gt;: Define project goals, milestones, and priorities. Ensure everyone is on the same page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pull Request Templates&lt;/strong&gt;: Create templates to guide contributors when opening PRs, making the process smoother.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Best Practices
&lt;/h2&gt;

&lt;p&gt;Good Git and GitHub practices make collaboration smoother and more efficient:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Descriptive Commit Messages&lt;/strong&gt;: Write clear and concise commit messages that explain what you did.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Branch Naming Conventions&lt;/strong&gt;: Follow a consistent branch naming convention. For example, use &lt;code&gt;feature/&lt;/code&gt; or &lt;code&gt;bugfix/&lt;/code&gt; prefixes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Clean Commit History&lt;/strong&gt;: Avoid messy commit histories by squashing related commits and keeping commits logically organized.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;

&lt;p&gt;Let's see these concepts in action with a few examples:&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 1: Feature Branch Workflow
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a feature branch: &lt;code&gt;git checkout -b feature/my-feature&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make changes, commit: &lt;code&gt;git commit -m "Add new feature"&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Push to GitHub: &lt;code&gt;git push origin feature/my-feature&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open a PR, request reviews, and make updates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Merge the PR when ready.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Example 2: Hotfix Branch Workflow
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a hotfix branch: &lt;code&gt;git checkout -b hotfix/urgent-fix&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make changes, commit: &lt;code&gt;git commit -m "Fix critical bug"&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Push to GitHub: &lt;code&gt;git push origin hotfix/urgent-fix&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open a PR, request reviews, and make updates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Merge the PR into &lt;code&gt;main&lt;/code&gt; and &lt;code&gt;develop&lt;/code&gt; branches.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;With these advanced techniques and best practices, you'll master Git and GitHub collaboration, ensuring smoother workflows and higher-quality code for your projects.&lt;/p&gt;

&lt;p&gt;Let me know your thoughts or questions in the comments!&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>GitHub 101: Cloning, Committing, and Creating New Branches</title>
      <dc:creator>Shubhankar Valimbe</dc:creator>
      <pubDate>Mon, 25 Sep 2023 21:01:54 +0000</pubDate>
      <link>https://forem.com/shubhankarval/github-101-cloning-committing-and-creating-new-branches-2l5f</link>
      <guid>https://forem.com/shubhankarval/github-101-cloning-committing-and-creating-new-branches-2l5f</guid>
      <description>&lt;p&gt;Hello beautiful people! &lt;/p&gt;

&lt;p&gt;Today I'm going to act as a chaperone on your journey to become a GitHub pro. If you're an experienced dev, you already know what it is. For the ones that don't, GitHub is a widely used platform for collaborating on code. This guide will walk you through the process of cloning a GitHub repository, making changes, and pushing those changes to both the main branch and a new branch.&lt;/p&gt;

&lt;p&gt;Before starting, please create an account on &lt;a href="https://github.com/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; if you don't already have one and install &lt;a href="https://git-scm.com/downloads" rel="noopener noreferrer"&gt;Git&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Cloning a GitHub Repository
&lt;/h2&gt;

&lt;p&gt;To get started, you'll need to clone an existing GitHub repository to your local machine. Follow these steps:&lt;/p&gt;

&lt;h3&gt;
  
  
  Navigate to directory
&lt;/h3&gt;

&lt;p&gt;Open your terminal or command prompt.&lt;/p&gt;

&lt;p&gt;Navigate to the directory where you want to store the cloned repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /path/to/your/desired/directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Copy Repo URL
&lt;/h3&gt;

&lt;p&gt;Click on the &lt;strong&gt;Code&lt;/strong&gt; button in the upper right corner of repo files and copy the HTTPS URL.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv6digam0t7g74yp3mqg5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv6digam0t7g74yp3mqg5.png" alt="Code Button" width="330" height="51"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3xr8669pmsbs5ahaswhl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3xr8669pmsbs5ahaswhl.png" alt="Clone URL" width="402" height="308"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Clone the repo
&lt;/h3&gt;

&lt;p&gt;Clone the repository using its HTTPS URL. Replace &lt;em&gt;username&lt;/em&gt; and &lt;em&gt;repository-name&lt;/em&gt; with the actual URL of the GitHub repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/username/repository-name.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Authenticate GitHub credentials
&lt;/h3&gt;

&lt;p&gt;Git will prompt you for your &lt;strong&gt;GitHub username and password&lt;/strong&gt; (or personal access token, if two-factor authentication is enabled) to authenticate and clone the repository.&lt;/p&gt;

&lt;p&gt;Once the clone is complete, you'll have a local copy of the Git repository in the directory you specified.&lt;/p&gt;




&lt;h2&gt;
  
  
  Making Changes
&lt;/h2&gt;

&lt;p&gt;With the repository cloned locally, you can now make changes to the code or files. You can edit, add, or delete files as needed.&lt;/p&gt;




&lt;h2&gt;
  
  
  Pushing Changes to the Main Branch
&lt;/h2&gt;

&lt;p&gt;To commit and push your changes to the main branch, follow these steps:&lt;/p&gt;

&lt;h3&gt;
  
  
  Stage the changes
&lt;/h3&gt;

&lt;p&gt;Stage the changes you want to commit. To stage all changes, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Commit Changes
&lt;/h3&gt;

&lt;p&gt;Commit the changes with a descriptive message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Your commit message here"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Push Changes
&lt;/h3&gt;

&lt;p&gt;Push the changes to the main branch on GitHub:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;






&lt;h2&gt;
  
  
  Creating and Pushing to a New Branch
&lt;/h2&gt;

&lt;p&gt;To create and push your changes to a new branch, do the following:&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a branch
&lt;/h3&gt;

&lt;p&gt;Create a new branch locally and switch to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; new-branch-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make and commit your changes in this new branch as shown above.&lt;/p&gt;

&lt;h3&gt;
  
  
  Push to new branch
&lt;/h3&gt;

&lt;p&gt;Push the new branch to GitHub and set up tracking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin new-branch-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;With these steps, you've successfully cloned a GitHub repository, made changes, and pushed those changes both to the main branch and a new branch. This workflow allows you to collaborate effectively on GitHub projects.&lt;/p&gt;

&lt;p&gt;Let me know your thoughts or questions in the comments!&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>DOM Manipulation with JavaScript: Bring Your Web Page to Life!</title>
      <dc:creator>Shubhankar Valimbe</dc:creator>
      <pubDate>Thu, 14 Sep 2023 09:07:33 +0000</pubDate>
      <link>https://forem.com/shubhankarval/dom-manipulation-with-javascript-bring-your-web-page-to-life-52n2</link>
      <guid>https://forem.com/shubhankarval/dom-manipulation-with-javascript-bring-your-web-page-to-life-52n2</guid>
      <description>&lt;p&gt;Hello beautiful people! &lt;/p&gt;

&lt;p&gt;Ever wondered how to make your web page interactive and dynamic? Well, that's where DOM &lt;em&gt;(Document Object Model)&lt;/em&gt; manipulation with JavaScript comes into play. In this quick read, we'll explore the basics of DOM manipulation and how it can add life to your web projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the DOM
&lt;/h2&gt;

&lt;p&gt;Before we dive into the magic of DOM manipulation, let's get the basics right. The DOM is a programming interface for web documents. It represents the structure of a web page and allows us to interact with its elements. Each HTML element on your page is a part of the DOM, and you can think of it as a tree-like structure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbs59hw1b25jpjrj9aehw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbs59hw1b25jpjrj9aehw.png" alt="DOM tree" width="768" height="600"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Accessing DOM Elements
&lt;/h2&gt;

&lt;p&gt;The first step in DOM manipulation is accessing the elements you want to work with. You can do this using JavaScript's &lt;strong&gt;document object&lt;/strong&gt;. For instance, to select an element with an &lt;em&gt;id&lt;/em&gt; of &lt;code&gt;myElement&lt;/code&gt; you can use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;myElement&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also select elements by class, tag name, or other attributes using methods like &lt;code&gt;querySelector&lt;/code&gt; and &lt;code&gt;querySelectorAll&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Modifying Elements
&lt;/h2&gt;

&lt;p&gt;Now that you've got your hands on an element, it's time to make some changes. Here are a few common operations:&lt;/p&gt;

&lt;h3&gt;
  
  
  Changing Text Content
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;New Text Content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Modifying HTML
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;p&amp;gt;This is a paragraph.&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Changing Styles
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fontSize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;20px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Adding or Removing Classes
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;new-class&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;old-class&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Handling Events
&lt;/h2&gt;

&lt;p&gt;DOM manipulation is not just about changing things; it's also about responding to user actions. You can use event listeners to make your page interactive. For example, to execute code when a button is clicked:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;myButton&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Button clicked!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Creating New Elements
&lt;/h2&gt;

&lt;p&gt;Sometimes, you may want to add new elements to your page dynamically. You can create elements using document.createElement and then append them to the DOM.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;newElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I am a new element&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newElement&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Removing Elements
&lt;/h2&gt;

&lt;p&gt;And, of course, you can remove elements too!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;elementToRemove&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;toBeRemoved&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;elementToRemove&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Putting It All Together
&lt;/h2&gt;

&lt;p&gt;With these basic tools, you can perform a wide range of DOM manipulations, from updating text and styles to adding, removing, and responding to elements. The DOM is your playground, and JavaScript is your tool to create amazing web experiences.&lt;/p&gt;

&lt;p&gt;So go ahead, experiment, and have fun bringing your web pages to life with DOM manipulation and JavaScript! 🚀&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>The React Revolution: Evolution of Syntax</title>
      <dc:creator>Shubhankar Valimbe</dc:creator>
      <pubDate>Sat, 09 Sep 2023 12:11:00 +0000</pubDate>
      <link>https://forem.com/shubhankarval/the-react-revolution-evolution-of-syntax-57eb</link>
      <guid>https://forem.com/shubhankarval/the-react-revolution-evolution-of-syntax-57eb</guid>
      <description>&lt;p&gt;Hey there, React lovers! If you've been around the JavaScript block for a while, you've probably witnessed the incredible evolution of React. From its humble beginnings to becoming the go-to library for building interactive web applications, React's syntax has undergone some fascinating changes. In this blog post, we'll take a stroll down memory lane and explore the evolution of React's syntax.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Birth of React
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;React 0.3.0 (May 29, 2013)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Back in the day, React's syntax was quite different. It all started with a &lt;code&gt;React.createClass&lt;/code&gt; method to define components, which looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createClass&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;render&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And rendering components was done like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Hello&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"World"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;,&lt;/span&gt; &lt;span class="nx"&gt;mountNode&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ES6 and the Class Component Revolution
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;React 0.13.0 (March 10, 2015)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React underwent a significant transformation with the introduction of ES6 classes. This change made defining components cleaner and more JavaScript-like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Hello&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ES6 class syntax made React code more readable and aligned with modern JavaScript practices. It also enabled the use of lifecycle methods directly in class components.&lt;/p&gt;




&lt;h2&gt;
  
  
  Functional Components
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;React 0.14.0 (October 7, 2015)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React introduced functional components, allowing developers to define components as pure functions. This syntax simplifies component creation when you don't need state or lifecycle methods:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Hello&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Functional components became the go-to choice for simple, stateless UI elements.&lt;/p&gt;




&lt;h2&gt;
  
  
  JSX Spread Attributes
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;React 16.2.0 (November 28, 2017)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React introduced a more convenient way to pass props using JSX spread attributes. It allowed for cleaner code when dealing with multiple props:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Hello&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This change made component composition and prop spreading more expressive.&lt;/p&gt;




&lt;h2&gt;
  
  
  Hooks: A Game Changer
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;React 16.8.0 (February 6, 2019)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Fast forward to 2019, and React unleashed hooks, a game-changing feature. Hooks let you use state and other React features without writing class components. Here's how you might use the useState hook:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Count: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Increment&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hooks offered more flexibility and reusability in functional components, ultimately simplifying React code.&lt;/p&gt;




&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;The evolution of React's syntax reflects its commitment to staying current and developer-friendly. Whether you prefer class components, functional components, or the power of hooks, React's flexibility allows you to choose the syntax that best suits your project's needs.&lt;/p&gt;

&lt;p&gt;As React continues to evolve, one thing remains constant: it's a powerhouse for building dynamic user interfaces on the web. So, whether you're nostalgic for the old ways or diving headfirst into the latest syntax, React has you covered. Happy coding!&lt;/p&gt;

</description>
      <category>react</category>
      <category>discuss</category>
      <category>community</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Event Handling in JavaScript</title>
      <dc:creator>Shubhankar Valimbe</dc:creator>
      <pubDate>Fri, 08 Sep 2023 21:41:08 +0000</pubDate>
      <link>https://forem.com/shubhankarval/event-handling-in-javascript-51n3</link>
      <guid>https://forem.com/shubhankarval/event-handling-in-javascript-51n3</guid>
      <description>&lt;p&gt;Hey there, JavaScript enthusiast! Ready to add some interactivity to your web page? Well, you're in the right place because today, we're diving into the exciting world of event handling in JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's an Event?
&lt;/h2&gt;

&lt;p&gt;Before we get into the nitty-gritty, let's talk about what an event is. In the web world, an event is basically something that happens – a click, a keypress, a mouse movement, you name it. These events can be captured and responded to using JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Event Listener
&lt;/h2&gt;

&lt;p&gt;To catch these events, we use something called an &lt;strong&gt;event listener&lt;/strong&gt;. It's like having a spy waiting for specific things to happen on your web page. When that something happens, the event listener jumps into action.&lt;/p&gt;

&lt;p&gt;Here's a simple example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#myButton&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Button clicked!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, we're telling JavaScript to listen for a &lt;em&gt;click&lt;/em&gt; event on the element with the id &lt;code&gt;myButton&lt;/code&gt;. When the button is clicked, a pop-up alert will appear saying 'Button clicked!'. Magic, right?&lt;/p&gt;

&lt;h2&gt;
  
  
  The Event Object
&lt;/h2&gt;

&lt;p&gt;Events can carry extra information with them, like where the mouse was when it was clicked. This additional info comes in an event object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#myElement&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;myElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mousemove&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Mouse coordinates: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clientX&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;clientY&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In this snippet, we're logging the mouse's X and Y coordinates whenever the mouse moves over &lt;code&gt;myElement&lt;/code&gt;. The &lt;strong&gt;event&lt;/strong&gt; object contains all the juicy details.&lt;/p&gt;

&lt;h2&gt;
  
  
  Removing Event Listeners
&lt;/h2&gt;

&lt;p&gt;Don't forget, you can also remove event listeners if you no longer need them. It's as simple as this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;removeListener&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;clickHandler&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;clickHandler&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;And there you have it – a quick tour of event handling in JavaScript! With event listeners and event objects in your toolkit, you can make your web page respond to user actions and create dynamic, interactive experiences.&lt;/p&gt;

&lt;p&gt;So go ahead, give it a try! Add some event handling magic to your website and make it come to life.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
