<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Untitled Publication]]></title><description><![CDATA[Untitled Publication]]></description><link>https://oigoga.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 15 Oct 2026 10:26:41 GMT</lastBuildDate><atom:link href="https://oigoga.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Exploring Vite's Features and Advantages for React Developers]]></title><description><![CDATA[Introduction
The need to improve the development experience and application performance drove the creation of Vite (pronounced "veet"). In this article, I will try my best to elaborate on how Vite can make your workflow better and how you can use it ...]]></description><link>https://oigoga.hashnode.dev/exploring-vites-features-and-advantages-for-react-developers</link><guid isPermaLink="true">https://oigoga.hashnode.dev/exploring-vites-features-and-advantages-for-react-developers</guid><category><![CDATA[React]]></category><category><![CDATA[vite]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[Oigoga Aba]]></dc:creator><pubDate>Fri, 06 Oct 2023 11:16:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1696590668282/cbe1ce8b-5412-404b-80c8-bd67ad8ea851.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>The need to improve the development experience and application performance drove the creation of Vite (pronounced "veet"). In this article, I will try my best to elaborate on how Vite can make your workflow better and how you can use it in your work.</p>
<h3 id="heading-what-is-vite">What is Vite?</h3>
<p>Vite means fast in French, and it has truly kept to its word. Founded by Evan You, the bright mind behind Vue.js, It was made with a developer in mind. Vite is designed to optimize the development experience and improve the runtime performance of web applications by leveraging modern JavaScript module loading features.</p>
<p>Here are some key features and concepts you should be aware of when working with Vite as a React developer:</p>
<ol>
<li><p><strong>Super Fast Development Server:</strong> Vite leverages native ES modules (ESM) and modern browsers' support to deliver rapid refreshes as you change your code base. This significantly speeds up your workflow over tools like Webpack</p>
</li>
<li><p><strong>Zero Configuration Setup:</strong> Vite minimizes configuration complexity. This means you can start a new project with zero configuration in most cases.</p>
</li>
<li><p><strong>Built-in ES Modules (ESM) Support:</strong> Vite supports ES modules. ES modules are a standardized way of working with modular code in JavaScript, providing a set of features and syntax for importing and exporting functions, classes, variables, and other JavaScript entities between different JavaScript files. This optimizes the production build size which is a priority for most projects</p>
</li>
<li><p><strong>Support for multiple JavaScript frameworks:</strong> While Vite was initially designed with Vue.js in mind, it can be used with other frameworks, including React. This makes it versatile, allowing you to choose the right tool for your project without compromising on development speed.</p>
</li>
<li><p>Vite's plugin system is based on the <a target="_blank" href="https://rollupjs.org/">Rollup</a> plugin system, which means it is highly flexible and capable of handling various aspects of your project's build and development process. This is particularly interesting because developers can create their own plugins or use existing ones from the Vite ecosystem.</p>
</li>
</ol>
<h3 id="heading-how-vite-improves-the-development-experience-for-react-developers"><strong>How Vite Improves the Development Experience for React Developers</strong></h3>
<p>Vite improves the development experience for developers in the following ways :</p>
<ul>
<li><p>Vite's fast development server with native ES modules support ensures quick feedback cycles, reducing the time spent waiting for builds and refreshes.</p>
</li>
<li><p>The zero-config setup minimizes the need for complex build configurations, making it easier for developers to get started with their React projects.</p>
</li>
<li><p>Vite offers built-in Hot Module Replacement, allowing React developers to see immediate changes in the browser without needing a full page refresh, which boosts productivity and reduces context-switching.</p>
</li>
<li><p>Vite's development tooling, including error overlay and debugging support, provides a smooth debugging experience for React applications.</p>
</li>
</ul>
<h3 id="heading-how-vite-improves-performance-and-speed-for-react-applications">How Vite Improves Performance and Speed for React Applications.</h3>
<p>Vite improves performance and speed for react applications using the following mechanisms</p>
<ol>
<li><p>By using native ES modules, Vite loads modules quickly, reducing startup time for development and improving runtime performance.</p>
</li>
<li><p>Vite automatically code-splits your application, ensuring that only the necessary modules are loaded when they are needed, resulting in faster page load times.</p>
</li>
<li><p>During production builds, Vite generates optimized bundles that are smaller in size, reducing the time it takes for users to download and run your application.</p>
</li>
</ol>
<p>Vite's development server and HMR capabilities minimize build times, allowing React developers to see changes instantly, thereby increasing productivity.</p>
<h2 id="heading-setting-up-a-react-project-with-vite"><strong>Setting Up a React Project with Vite</strong></h2>
<p>Having been introduced to what Vite is and how it helps us as developers, it is important to know how to use it to set up a react project with Vite.</p>
<p><strong>Step 1: Install Node.js</strong> To use Vite, you have to have Node.js installed on your system. This can be installed from the official node.js <a target="_blank" href="https://nodejs.org/en">website</a>.</p>
<p><strong>Step 2: Create a new Vite project.</strong> To create a new project with Vite, open your terminal and navigate to the proper folder where you want your project located, and run the following: <em>Note that my-react-app should be replaced with the name of your project.</em></p>
<pre><code class="lang-bash">npm init vite@latest my-react-app -- --template react
<span class="hljs-built_in">cd</span> my-react-app
</code></pre>
<p><strong>Step 3: Start the Development Server</strong></p>
<p>After navigating to the project directory, the development server can be started by running</p>
<pre><code class="lang-bash">npm run dev
</code></pre>
<p><strong>Step 4: Begin Development.</strong> You're now ready to start building your React application. Vite automatically handles module loading, hot module replacement, and many other development tasks, making your development process fast and efficient.</p>
<h3 id="heading-customizing-your-vite-react-project">Customizing Your Vite + React Project.</h3>
<p>Although Vite has a zero config setup, you may need to customize your project as it grows or to fit specific requirements. Here's how you can do that:</p>
<p>To customize Vite settings, if it was not automatically created while creating the vite project, create a <code>vite.config.js</code> file in the root of your project. In this file, you can specify various options, such as customizing the build output directory, configuring plugins, and more. Here's an example of a basic <code>vite.config.js</code> file:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// vite.config.js</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
  <span class="hljs-comment">// Custom configurations go here</span>
}
</code></pre>
<p><strong>Using Plugins:</strong> Vite's plugin system allows you to enhance your development workflow by integrating various plugins. For example, you can use the <code>@vitejs/plugin-react</code> plugin to optimize React support in your project. To use this plugin, install it first:</p>
<pre><code class="lang-bash">npm install --save-dev @vitejs/plugin-react
</code></pre>
<p>Then include it in your <code>vite.config.js</code> file.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// vite.config.js</span>
<span class="hljs-keyword">import</span> { defineConfig } <span class="hljs-keyword">from</span> <span class="hljs-string">'vite'</span>;
<span class="hljs-keyword">import</span> react <span class="hljs-keyword">from</span> <span class="hljs-string">'@vitejs/plugin-react'</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> defineConfig({
  <span class="hljs-attr">plugins</span>: [react()],
});
</code></pre>
<p><strong>Customizing Babel and ESLint</strong></p>
<p>You can also customize Babel and ESLint configurations in your Vite project. Create <code>.babelrc</code> and <code>.eslintrc.js</code> files in your project's root directory to add your custom rules and settings.</p>
<p><strong>Building for Production</strong></p>
<p>When you're ready to deploy your React application, you can create a production-ready build by running:</p>
<pre><code class="lang-bash">npm run build
</code></pre>
<p>This command will generate an optimized production build of your application, including minified and bundled JavaScript, CSS, and other assets. You can find the output in the <code>dist</code> directory.</p>
<h3 id="heading-best-practices-for-using-vite-with-react"><strong>Best Practices for Using Vite with React</strong></h3>
<p>Here are some best practices to consider when using Vite with React:</p>
<p><strong>Keep Dependencies Updated:</strong> Regularly update your project's dependencies, including Vite and React, to benefit from the latest features and security fixes.</p>
<p><strong>Use Plugins Wisely:</strong> Leverage Vite plugins to enhance your development workflow, but avoid excessive plugin usage, which can complicate your project.</p>
<p><strong>Optimize for Production:</strong> Pay attention to Vite's production build settings, such as minification and code splitting, to ensure your React application is optimized for deployment.</p>
<p><strong>Modular Code:</strong> Embrace modular code practices in your React application, as Vite's native ESM support encourages this approach.</p>
<p><strong>Explore Vite's Documentation:</strong> Familiarize yourself with Vite's documentation to discover additional features and configurations that can improve your React development experience.</p>
<p>By understanding these benefits, improvements, and best practices, React developers can make the most of Vite to streamline their development workflow and create high-performance applications more efficiently. Vite is a powerful development tool that can greatly enhance your React development experience. Its speed, native ES modules support, and flexible configuration options make it an excellent choice for modern web development projects.</p>
]]></content:encoded></item><item><title><![CDATA[Choosing Between Class and Functional Components in React]]></title><description><![CDATA[Introduction
React is an open-source library popularly used for building interfaces. React provides developers with a structured and efficient way to create interactive and very dynamic UI components. At its core React operates on the principle of co...]]></description><link>https://oigoga.hashnode.dev/choosing-between-class-and-functional-components-in-react</link><guid isPermaLink="true">https://oigoga.hashnode.dev/choosing-between-class-and-functional-components-in-react</guid><category><![CDATA[React]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[Oigoga Aba]]></dc:creator><pubDate>Thu, 14 Sep 2023 16:16:18 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1694707741099/bf6ac9e3-a47b-4ea7-8619-f3f331e3bea0.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>React is an open-source library popularly used for building interfaces. React provides developers with a structured and efficient way to create interactive and very dynamic UI components. At its core React operates on the principle of component-based architecture. This means you can break down the User Interface into bite-sized reusable pieces of code called components. This makes it easier to manage and maintain complex applications.</p>
<h2 id="heading-what-are-these-components">What are these components?</h2>
<p>Components are the building blocks of a user interface. They are self-contained and reusable pieces of code that can contain a specific part of functionality and presentation. When building an application, various components have to be put together to make the whole application work properly or as intended. Although these components work in conjunction with each other, they are all independent.</p>
<h2 id="heading-types-of-react-components">Types of React Components</h2>
<p>There are mainly two types of react components</p>
<ol>
<li><p>Class Components</p>
</li>
<li><p>Functional Components</p>
</li>
</ol>
<h2 id="heading-class-components">Class Components</h2>
<p>Class components are Javascript classes that make use of the ES6 syntax to extend the 'React.component' class. This was the initial way of defining components in React before the functional components and hooks were introduced. Class components can be referred to as smart or stateful as they were used to implement logic and state before the introduction of hooks. Using the "this" keyword, props could be passed down from parent to child components.</p>
<h3 id="heading-the-anatomy-of-the-class-component"><strong>The Anatomy of the Class Component</strong></h3>
<p>The key features of a class component are discussed below.</p>
<p><strong>The Class declaration</strong></p>
<p>The class component usually starts with a declaration that extends the <code>React.component</code> as shown below.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> react, {Component} <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Article</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span> </span>{

}
</code></pre>
<p><strong>The Constructor</strong></p>
<p>This is used to initialize the state of the component and bind event handlers to the component. The code below shows the constructor. This receives props as an argument to represent the initial properties passed from the parent element to this component. The next line shows <code>super(props)</code>' which calls the constructor of the parent class <code>React.Component</code> and passes the props to it. This is required to properly initialize the component and make sure that React sets up the props correctly. The component's state is initialized with <code>this.state = { count: 0 }</code> where <code>state</code> is an object that holds data that can change over time and trigger updates to the component's UI when it does. In this case, it initializes the <code>count</code> property to 0, which will be used to keep track of a count in the component's state. The last line: <code>this.handleClick = this.handleClick.bind(this)</code> binds the <code>this</code> context to the <code>handleClick</code> method.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">constructor</span>(props) {
  <span class="hljs-built_in">super</span>(props);
  <span class="hljs-built_in">this</span>.state = {
    <span class="hljs-attr">count</span>: <span class="hljs-number">0</span>,
  };
  <span class="hljs-built_in">this</span>.handleClick = <span class="hljs-built_in">this</span>.handleClick.bind(<span class="hljs-built_in">this</span>);
}
</code></pre>
<p><strong>The render method</strong></p>
<p>This returns the JSX representation of the component's UI.</p>
<pre><code class="lang-javascript">render() {
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Count: {this.state.count}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{this.handleClick}</span>&gt;</span>Increment<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}
</code></pre>
<p><strong>State Management</strong></p>
<p>Class components manage their states using <code>this.state</code>. This is used to store and update data over time thus making them dynamic. The code below updates the count property with an increment of 1.</p>
<pre><code class="lang-javascript">handleClick() {
  <span class="hljs-built_in">this</span>.setState({ <span class="hljs-attr">count</span>: <span class="hljs-built_in">this</span>.state.count + <span class="hljs-number">1</span> });
}
</code></pre>
<p><strong>Lifecycle Methods</strong></p>
<p>Class components also have lifecycle methods that allow developers to hook into the different stages of a component's lifecycle. These methods enable you to perform actions like initialization, data fetching, DOM manipulation, and cleanup.</p>
<h2 id="heading-functional-components">Functional Components</h2>
<p>With the development of React hooks, functional components became more popular as its limitation was the ability to manage states. Functional components are javascript functions that return JSX to define and render a user interface. Because of their simplicity and readability, they are now preferred over class components although for larger-scale applications where you need more control over the component's lifecycle, the class component is preferred.</p>
<h3 id="heading-the-basic-structure-of-functional-components"><strong>The Basic Structure of Functional Components.</strong></h3>
<p><strong>Function Declaration.</strong></p>
<p>At its core, the functional component is a Javascript function and with the development of the ES6 syntax it can also be defined as an arrow function</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Regular function</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Article</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> (
        <span class="hljs-comment">// JSX goes here</span>
      )
}

<span class="hljs-comment">//Arrow function</span>
<span class="hljs-keyword">const</span> Article = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-keyword">return</span> (
    <span class="hljs-comment">// JSX goes here</span>
  )
}
</code></pre>
<p><strong>Component Logic</strong></p>
<p>Within the body of the function, you can write Javascript code to define the component's behavior with respect to other components or within itself.</p>
<p>The JSX return statement is the most crucial part of the component as the User Interface is rendered here.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Article</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> username = <span class="hljs-string">"John"</span>;
  <span class="hljs-keyword">const</span> greetingMessage = <span class="hljs-string">`Hello, <span class="hljs-subst">${username}</span>!`</span>;

  <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>{greetingMessage}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>;
}
</code></pre>
<p><strong>The Export Statement</strong></p>
<p>The export statement makes the component accessible to other parts of the application. The <code>export</code> keyword is used and when it is the only component being exported from the file, the <code>export default</code> keyword can be used.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Article</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// Component logic and JSX rendering</span>
}
<span class="hljs-comment">// OR</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Article</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// Component logic and JSX rendering</span>
}
</code></pre>
<h2 id="heading-functional-components-vs-class-components">Functional Components Vs Class Components</h2>
<p>They both have their highlights/benefits and drawbacks. They are discussed below.</p>
<h3 id="heading-highlights">Highlights</h3>
<p><strong>Functional Components</strong></p>
<ol>
<li><p>They are simpler and more concise than class components, making them easier to read and understand and they are an excellent choice, especially for beginners.</p>
</li>
<li><p>They do not use the <code>this</code> keyword thereby making your code more predictable and reducing the chances of bugs in your code.</p>
</li>
<li><p>Although they are referred to as 'dumb' and 'stateless', they work seamlessly with React hooks allowing them to manage states effectively.</p>
</li>
<li><p>They encourage the creation of reusable UI elements. They are more modular, making it easier to compose and share code between different parts of your application.</p>
</li>
<li><p>With React's <code>React.memo</code> and other optimization techniques, functional components can be optimized to minimize unnecessary re-renders, improving application performance.</p>
</li>
<li><p>Functional components promote immutability and pure functions and this leads to cleaner and more maintainable code. This aligns well with the <a target="_blank" href="https://www.geeksforgeeks.org/functional-programming-paradigm/">functional programming paradigm</a></p>
</li>
<li><p>Because the React community has shifted its focus toward functional components and hooks, there are more resources, tutorials, and community support available for developers using functional components.</p>
</li>
</ol>
<p><strong>Class Components</strong></p>
<ol>
<li><p>Class components have access to React's lifecycle methods, such as <code>componentDidMount</code>, <code>componentDidUpdate</code>, and <code>componentWillUnmount</code>. These methods allow for fine-grained control over component behavior during its lifecycle.</p>
</li>
<li><p>They can store instance-specific data in their state, making them suitable for scenarios where you need to manage complex states with multiple properties.</p>
</li>
<li><p>They are also still widely used in existing React codebases, and they continue to be supported by the React library. They can be essential for maintaining and updating legacy projects which are essentially older projects with outdated technology stacks or limited documentation.</p>
</li>
<li><p>Class components explicitly define the component's structure and behavior, which can be advantageous when working on projects where clarity and explicitness are essential.</p>
</li>
<li><p>Class components are well-suited for certain advanced patterns, such as implementing higher-order components (HOCs) and creating custom render methods.</p>
</li>
</ol>
<h3 id="heading-drawbacks">Drawbacks</h3>
<p><strong>Functional Components</strong></p>
<ol>
<li><p>Functional components couldn't use lifecycle methods until the introduction of React 18 (Concurrent Mode). This could make it challenging to manage side effects and component updates in complex scenarios.</p>
</li>
<li><p>They don't have a <code>this</code> keyword. While this can be seen as a benefit, it can also be a limitation when you need to access instance-specific data or methods.</p>
</li>
<li><p>Sharing logic between functional components can be less intuitive compared to class components using higher-order components (HOCs) or render props. Although custom hooks have improved this aspect, it can still be more complex than class component reuse.</p>
</li>
<li><p>Passing props down multiple levels of nested components (prop drilling) can become cumbersome and lead to less readable code. This is particularly frustrating based on my experience.</p>
</li>
</ol>
<p><strong>Class Component</strong></p>
<ol>
<li><p>Class components can be more complex than functional components. They require a constructor for state initialization and lifecycle methods like <code>componentDidMount</code>, <code>componentDidUpdate</code>, etc., which can make the code harder to follow. This is a benefit but it is also a drawback.</p>
</li>
<li><p>They may have performance implications due to their reliance on lifecycle methods. For example, unnecessary re-renders can occur if not managed carefully.</p>
</li>
<li><p>Class components tend to be more verbose than functional components. This verbosity can make the code harder to read and maintain, especially in larger projects.</p>
</li>
<li><p>For developers new to React, understanding class components, their lifecycle methods, and the <code>this</code> keyword can pose a steeper learning curve compared to functional components.</p>
</li>
<li><p>With the introduction of hooks, the React community has shifted its focus towards functional components. This means that class components may receive less attention in terms of updates, improvements, and community resources.</p>
</li>
</ol>
<h2 id="heading-conclusion">Conclusion</h2>
<p>As a developer, the choice of component type to use is not determined by which type has more pros or cons. This balls down to the particular use case, project requirements, and your preferences. While functional components have become increasingly popular in many modern React applications, Class components remain relevant, especially in cases where their unique capabilities are needed or when dealing with existing codebases.</p>
]]></content:encoded></item></channel></rss>