Web Development Marathon — React vs Svelte

dilarauluturhan
folksdev
7 min readMar 21, 2024

--

Web development is constantly changing shape with innovative technologies. I continue to learn and code React and Svelte, two of these innovative technologies. The fact that React is very popular and has a large community, and Svelte’s innovative and performance-oriented approach, make both of them attractive. So let’s dive into the comparison between these two giant technologies!🫧

Topics of this article:

  1. Main Purposes of React and Svelte
  2. Community Support of React and Svelte
  3. Same Aspects of React and Svelte
  4. Different Aspects of React and Svelte
  5. Use Case — Counter Button with React and Svelte

Main Purposes of React and Svelte✨

React is a JavaScript library developed by Facebook and first announced in 2013. The Facebook developer team developed React to manage large-scale and complex user interfaces more effectively. React offers a component-based structure. In this way, it makes development easier by separating the user interface into reusable components. Perhaps the most striking feature of React is its use of virtual DOM. This allows React to minimize changes to the actual DOM and improve performance.

Svelte is a JavaScript framework developed by Rich Harris and first announced in 2016. Although Svelte announced its first version in 2016, its big breakthrough came in 2019 with the announcement of Svelte 3. The release of Svelte 3 aroused great interest among developers and quickly became popular in the field of web development. Svelte offers a feature that automatically keeps track of the variables used within components and triggers a re-render of the component when the value of the variables changes. It also compiles the code at compile time. In this way, the applications created are faster.

Community Support of React and Svelte✨

React has an extremely large and active community. This open source project announced by Facebook is supported by many developers. In addition to community support, it is also rich in documentation and learning resources. I think that the resources and sample applications on React’s official website are very educational for someone who is just starting to learn.

React npm weekly downloads
React GitHub stars

Although Svelte is a newer technology, it has a rapidly growing community. The community is also active on platforms like Reddit and Discord, engaging with developers to answer questions, share projects, and share experiences regarding Svelte. I think that the resources and sample applications on Svelte’s official website are very instructive and guiding for someone who is just starting to learn.

Svelte npm weekly downloads
Svelte GitHub stars

There are some differences between React and Svelte’s community support. Of course, React has a long history and a large user base. This results in a large pool of resources and a comprehensive ecosystem, but Svelte has a rapidly growing community and innovative approach that could make it even more popular in the future.

Community support in project selection is important for the efficiency of your development process and the speed of solving problems. While both React and Svelte have strong communities, it’s important to consider these factors to choose the one that best suits your project’s needs.

Same Aspects of React and Svelte✨

Although React and Svelte have different features, they also have some common aspects. Both take a component-based approach. The component-based approach makes the code more modular and manageable.

Both React and Svelte have a rich ecosystem. Both technologies are supported by various helper libraries and plugins. This ecosystem allows us developers to build and extend the application faster and more efficiently.

Both technologies prioritize performance. React’s virtual DOM update strategy and Svelte’s compile-time optimization ensure applications are fast and efficient. This allows users to have a better experience and developers to develop applications faster using fewer resources.

These commonalities of React and Svelte show that both technologies are strong players in the field of web development.

https://pagepro.co/blog/react-vs-svelte/

Different Aspects of React and Svelte✨

React and Svelte are two important technologies with different approaches. Both offer powerful tools for building modern web applications, but they have different features and approaches.

React creates components using JSX (JavaScript XML) and creates user interfaces through this component. In the component example below, the component named Profile() is called in the Gallery() component.

https://react.dev/learn/describing-the-ui#your-first-component

Svelte creates components using an HTML-like syntax. It transforms the component into optimized JavaScript code and increases performance by ensuring that the code runs at compile time rather than at run time. As you can see below, creating a Svelte component is just like writing HTML.

https://learn.svelte.dev/tutorial/your-first-component

React detects changes between components using the virtual DOM and updates the DOM only when necessary. Svelte improves performance by converting components into optimized JavaScript code at compile time. This ensures that the application requires less processing at runtime and loads faster.

React uses libraries like Redux for complex state-management scenarios. On the other hand, Svelte offers reactivity functions in state management scenarios, potentially reducing dependency on additional libraries.

What is Reactivity?

Svelte presents the concept of reactivity in a simpler way than other frameworks. It allows the component to be automatically re-rendered when the state of the variables changes.
For more information about Reactivity, you can get information from my Medium article, the link of which is below.👇

React has a large ecosystem suitable for a wide range of applications, but React projects can often be larger in size and require more setup at the beginning. Svelte is smaller in size and has less of a learning curve. Svelte projects can often be smaller in size and have fewer dependencies.

The different aspects of React and Svelte mean that both technologies appeal to developers with different use cases and preferences. We, as developers, must take these differences into account when choosing the technology that best suits our needs.

Use Case — Counter Button with React and Svelte✨

We talked about a lot of theoretical issues, let’s look at some code blocks. I prepared counter-button codes to compare React and Svelte. Let’s examine these now:

Let’s start with React first. If we look at the codes below,

We used the useState hook to manage the state of components in React. In this example, I created a state named count and assigned 0 as the initial value. We use the setCount function to update this state.

We use the increment and decrement functions to increase and decrease the counter value. Both functions update the count state by calling the setCount function.

import React, { useState } from "react";

function Counter() {
const [count, setCount] = useState(0);

const increment = () => setCount(count + 1);
const decrement = () => setCount(count - 1);

return (
<div>
<button onClick={increment}>+</button>
<span>{count}</span>
<button onClick={decrement}>-</button>
</div>
);
}
export default Counter;

In this way, the Counter component shows us a counter and updates the counter value with the increase/decrease buttons. In this simple example, state management is provided with the useState hook, while the counter value is updated with the increment and decrement functions. In this way, the component responds dynamically to user interaction. Let’s look at the code output:

Now let’s create the same component with Svelte. In these codes, Svelte takes a simpler approach. Creating a variable in Svelte (let count = 0) corresponds to creating a state in React. Let’s examine the counter button codes we created with Svelte:

count is a variable that holds the counter value. I assigned 0 as the initial value, and the counter value will be updated through this variable. We use increment and decrement functions to increase and decrease the counter value. Both functions increase or decrease the count variable.

<script>
let count = 0;

function increment() {
count++;
}

function decrement() {
count--;
}
</script>

<button on:click={increment}>+</button>
<span>{count}</span>
<button on:click={decrement}>-</button>

Creating a counter with Svelte is that easy. This way, we can create a simple counter using JavaScript and create the user interface with HTML. Let’s look at the code output:

As a result, in this article, we examined both the similar and different aspects of React and Svelte. We examined how it works through the case. Both technologies have their own advantages and disadvantages. React is popular for having a large community and a developed ecosystem. In contrast, Svelte focuses on performance and speed, with compile-time optimization and a simple syntax. Which technology is preferred depends on the needs of the project, the experience of the team, and personal preferences. Both technologies are strong players in modern web development, offering flexibility and options to developers. React and Svelte both offer advantages suitable for different use cases and are worth considering in web development projects.

If you have questions, comments, or topic suggestions, please let me know. Your feedback helps me further improve my blog series. See you in the next article!

Click if you want to contact me!👩🏻‍💻

You can support my articles by buying a coffee.☕️

--

--