ReactJS vs Svelte

Introduction

Frontend development is an ever-evolving niche in tech like any other tech field, it has many frameworks and libraries to choose from.

These frameworks and libraries are the frontend technologies to enable us frontend developers to create appealing eye catching user interface that the end user feel comfortable using

In this article, we will be looking into two popular frontend technologies: ReactJs and Svelte. We'll explore their differences, advantages, and disadvantages

Overview of ReactJS

ReactJS is a JavaScript library developed by Facebook for building splendid user interfaces. It is widely used due to its high demand in the tech industry and component-based architecture, which promotes reusability and easy management of complex UIs.

Key Features of ReactJS:

Below are some of the key features of ReactJs:

  • Components: ReactJS is based on a component-based architecture, where the user interface is broken down into small, reusable components. Each component is responsible for rendering a specific part of the UI. In other words, it's modular in structure.

  • JSX: ReactJS uses JSX, a syntax extension for JavaScript that allows you to write HTML-like code in your JavaScript files. This makes it easier to create and manage UI components.

  • Virtual DOM: ReactJS uses a virtual DOM (Document Object Model) to optimize rendering and improve performance. The virtual DOM is a lightweight in-memory representation of the real DOM, which is updated and then diffed with the real DOM to determine what changes need to be made.

  • One-way Data Binding: ReactJS uses one-way data binding, which means that components only receive updates from their parents and do not directly modify the state of their parents.

  • State and Props: ReactJS components have their own state and props, which are used to manage the component’s data and behavior.

Overview of Svelte

Svelte is a relatively new framework that takes a different approach to building web applications. Unlike React, which does most of its work in the browser, Svelte shifts that work into a compile step that happens during the build process. This results in highly optimized and efficient code.

Key Features of Svelte

Below are some of the key features of svelte

  • Efficient Code: Svelte’s compiler approach results in smaller file sizes and improved speed, making it ideal for mobile device users.

  • Concise Components: Svelte allows developers to write concise components using HTML, CSS, and JavaScript, reducing the amount of code required and minimizing potential bugs and improving code readability.

  • No Virtual DOM: Unlike other frameworks, Svelte does not require loading an entire library in the browser, reducing the size of the file and overhead generated by the virtual DOM.

  • Build-Time Optimization: Svelte shifts as much work as possible out of the browser and into the build step, resulting in faster, more efficient apps.

Differences and Comparisons

We will be looking at few difference between these two technologies

  • Rendering User Interface: ReactJs uses a runtime called the virtual DOM, it keeps track of data changes in the application in order to render them in the actual DOM of the browser. Svelte takes an entirely different approach as it uses a compiler to elimate the need for a runtime (it takes your svelte code and converts them into vanilla javascript)

  • Community and Ecosystem: ReactJs Has a large and mature ecosystem with extensive community support, numerous libraries, and tools. while Svelte is Smaller but rapidly growing community. The ecosystem is not as extensive as React’s but is steadily expanding.

  • Prop passing: To pass props in react we do so by defining them as a function argument

      function ColorComponent({color}) {
    
          return (
              <p>You picked: {color} </p>
              )
      }
    

    in Svelte, things look a lot different, putting the export keyword infront a varaible allows it to be in passed in from the out slide

      ...
      <script>
         export let color;
      </script>
      ...
      You picked: {color}
    
  • Passing components as props: You can only do this in reactjs and not in svelte as you'd need to use something called SLOTS which takes a longer process.... (*sighs in disappointment)

Unto the next ....urgghhh

Advantages and Disadvantages

ReactJs:

Merit: Via it's large ecosystem, and strong community support, you can always a find a solution to an issue you encounter.

Demerit: It requires an understanding of additional concepts like JSX and state management libraries

Svelte:

Merit: What make this technology stand out, is it's simplicity, fast performance, minimal boilerplate, and built-in state management.

Demerit: There are fewer resources on this technology and as such can be difficult to get solutions to an issue you might encounter

Conclusion: Which is Better

Ok, I know most of you will be pointing a gun at me right now as which is better 😂😂😂

Alright, it depends on what you want to build, for more robust applications, I would personally go for Reactjs and for simpler and more modern approach to frontend development, I would go for Svelte.

ALRIGHTY!! now please put the gun away 😂🙏

Expectations and Feelings about Using ReactJS in HNG

In the HNG Internship, I look forward to building sophisticated and scalable applications, using ReactJS. The opportunity to collaborate with other talented developers and contribute to real-world projects is something I eagerly anticipate. I believe that my experience with ReactJS during the HNG internship will be both challenging and rewarding, and I am enthusiastic about what is to come.

For more information about the HNG Internship, visit the HNG Internship website and explore how you can hire talented interns.

13
Subscribe to my newsletter

Read articles from Daniel Nwachukwu Chigozirim directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Daniel Nwachukwu Chigozirim
Daniel Nwachukwu Chigozirim

Web3 Front-end developer || Smart contract developer || Tech enthusiast || Let's talk web 🕸️ || GitHub - http://github.com/Verifieddanny