<?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: Tejas Bhadane</title>
    <description>The latest articles on DEV Community by Tejas Bhadane (@codewithtejas).</description>
    <link>https://dev.to/codewithtejas</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%2F1807589%2F90dc25aa-a5c5-4ca7-855d-35391810f159.jpeg</url>
      <title>DEV Community: Tejas Bhadane</title>
      <link>https://dev.to/codewithtejas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codewithtejas"/>
    <language>en</language>
    <item>
      <title>My 2 cents on react &amp; next</title>
      <dc:creator>Tejas Bhadane</dc:creator>
      <pubDate>Fri, 19 Jul 2024 18:35:39 +0000</pubDate>
      <link>https://dev.to/codewithtejas/getting-my-hands-dirty-with-react-next-1hg</link>
      <guid>https://dev.to/codewithtejas/getting-my-hands-dirty-with-react-next-1hg</guid>
      <description>&lt;h2&gt;
  
  
  Why I’m Diving into React and Next.js: A Fresh Start
&lt;/h2&gt;

&lt;p&gt;I’ve recently embarked on a new learning journey with React and Next.js, and here’s why I’m excited about these tools:&lt;/p&gt;

&lt;h3&gt;
  
  
  React: The Why
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Component-Based Magic
&lt;/h4&gt;

&lt;p&gt;React’s component-based architecture has been a game-changer for me. Instead of managing tangled code, I’m now creating reusable, self-contained components. For example, a simple Button component looks 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;// Button.js
import React from 'react';

const Button = ({ onClick, children }) =&amp;gt; (
  &amp;lt;button onClick={onClick}&amp;gt;{children}&amp;lt;/button&amp;gt;
);

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

&lt;/div&gt;



&lt;p&gt;This modular approach not only streamlines development but also keeps my projects more organized.&lt;/p&gt;

&lt;h4&gt;
  
  
  Declarative and Clear
&lt;/h4&gt;

&lt;p&gt;React’s declarative syntax is a breath of fresh air. It lets me describe what the UI should look like based on the application’s state, leading to cleaner and more predictable code. Here’s a simple Counter component:&lt;br&gt;
&lt;/p&gt;

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

const Counter = () =&amp;gt; {
  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;
  );
};

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Awesome Ecosystem
&lt;/h4&gt;

&lt;p&gt;The React ecosystem is rich with tools and libraries. For routing, React Router simplifies navigation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// App.js
import React from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import Home from './Home';
import About from './About';

const App = () =&amp;gt; (
  &amp;lt;Router&amp;gt;
    &amp;lt;Switch&amp;gt;
      &amp;lt;Route path="/" exact component={Home} /&amp;gt;
      &amp;lt;Route path="/about" component={About} /&amp;gt;
    &amp;lt;/Switch&amp;gt;
  &amp;lt;/Router&amp;gt;
);

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Performance Boost
&lt;/h4&gt;

&lt;p&gt;React’s virtual DOM efficiently updates the UI. Here’s a simple component that showcases React’s performance optimizations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// UserProfile.js
import React from 'react';

const UserProfile = ({ user }) =&amp;gt; (
  &amp;lt;div&amp;gt;
    &amp;lt;h1&amp;gt;{user.name}&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;{user.email}&amp;lt;/p&amp;gt;
  &amp;lt;/div&amp;gt;
);

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Next.js: The Bonus
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Built-In Features
&lt;/h4&gt;

&lt;p&gt;Next.js extends React with built-in features like server-side rendering and static site generation. Here’s a basic page setup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// pages/index.js
import React from 'react';

const HomePage = () =&amp;gt; (
  &amp;lt;div&amp;gt;
    &amp;lt;h1&amp;gt;Welcome to Next.js!&amp;lt;/h1&amp;gt;
  &amp;lt;/div&amp;gt;
);

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  File-Based Routing
&lt;/h4&gt;

&lt;p&gt;Next.js uses a file-based routing system, where the structure of the pages directory determines the routes. For example:&lt;/p&gt;

&lt;p&gt;pages/index.js maps to /&lt;br&gt;
pages/about.js maps to /about&lt;br&gt;
For dynamic routes, create files with square brackets. For instance, pages/users/[id].js handles URLs like /users/123:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// pages/users/[id].js
import { useRouter } from 'next/router';

const UserProfile = () =&amp;gt; {
  const router = useRouter();
  const { id } = router.query;

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;User Profile for User ID: {id}&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Optimized Performance
&lt;/h4&gt;

&lt;p&gt;Next.js includes performance optimizations like automatic code splitting and optimized image loading. Here’s how you can use the next/image component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// pages/index.js
import Image from 'next/image';

const HomePage = () =&amp;gt; (
  &amp;lt;div&amp;gt;
    &amp;lt;h1&amp;gt;Next.js Image Optimization&amp;lt;/h1&amp;gt;
    &amp;lt;Image src="/my-image.jpg" alt="My Image" width={500} height={300} /&amp;gt;
  &amp;lt;/div&amp;gt;
);

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  In a Nutshell
&lt;/h3&gt;

&lt;p&gt;React’s component-based approach and declarative syntax, combined with Next.js’s powerful features and intuitive file-based routing, make for an exciting development experience. I’m thrilled to explore more and see where this journey with React and Next.js takes me!&lt;/p&gt;

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