Marcell Ciszek Druzynski
← Back to blog posts

Why React?

JavaScript frameworks and libraries abound for building frontend and full-stack applications. However, the abundance of options can lead to feelings of overwhelm. Each developer has their own preferences and often advocates for their preferred tools.

My purpose is not to debate the superiority of frameworks or libraries. Instead, I intend to explore why I consistently return to React, even after exploring other notable frameworks. I aim to elucidate why React remains my preferred choice.

What distinguishes React for me when embarking on a new project? One reason is its familiarity and comfort in writing in React. It is the framework I use professionally and the first JavaScript framework I learned. Over the past six years, React has become an integral part of my workflow. While I acknowledge its shortcomings, I also appreciate its advantages.

Advantages of React

Virtual DOM The virtual DOM enables React to update only the modified sections of the real DOM, rather than rendering the entire page or large sections. This selective updating is achieved through a process called “diffing” and reconciliation, which compares the new virtual DOM with the previous one and applies only the necessary changes. Direct manipulation of the real DOM can be slow, especially for complex, interactive applications. The virtual DOM minimizes direct DOM operations, reducing costly browser reflows and repaints, thereby improving performance for dynamic UIs. Developers can describe the desired UI for a given state, and React ensures that the DOM matches that state. This abstraction simplifies development, reduces bugs, and makes code more predictable and maintainable.

React’s Evolution: React has evolved significantly since its introduction. The shift from class-based components to functional components with hooks has made React code more concise and readable, while also reducing boilerplate. Hooks like useState and useEffect have become standard for managing state and side effects, further simplifying component logic.

Areas for Improvement in React

Best Practices for Maintainable React Code:

Exploring Other Frameworks:

I have experimented with other notable JavaScript frameworks, such as Svelte, Solid, and Vue.js, to gain insights into their rendering, state management, and data fetching approaches. All contemporary frameworks adhere to the component-based principle, enabling developers to construct reusable components, which has become a standard in contemporary UI development.

Vue employs a virtual DOM, akin to React. In contrast, Svelte and Solid adopt distinct methodologies. Svelte compiles components at build time into highly optimized JavaScript code that directly updates the real DOM. It analyzes code during compilation and generates imperative code that precisely identifies the DOM modifications required upon state changes. This eliminates the necessity for runtime diffing and patching associated with virtual DOM frameworks like React or Vue. When a reactive variable modifies, Svelte updates only the affected DOM elements, resulting in enhanced performance and reduced bundle sizes.

SolidJS also avoids utilizing a virtual DOM. Instead, it employs a granular reactivity system that directly updates the real DOM. SolidJS utilizes reactive primitives known as “signals” to track dependencies. When a signal undergoes a change, only the specific DOM nodes reliant on that signal are updated, rather than re-rendering entire components or employing a diffing algorithm. SolidJS leverages compile-time optimizations and a runtime reactive system, ensuring rapid updates and minimizing performance overhead.

Summary and Advice

Occasionally, I perceive React as my primary framework due to its exceptional tooling, libraries, and vibrant community. Nevertheless, I consistently find myself drawn back to React. While exploring alternative frameworks and tools can be rewarding, I encounter recurring frustrations. Although these frameworks and tools may offer advantages, they often come with trade-offs. Even if a new framework asserts its superiority in terms of speed and efficiency, it may introduce unforeseen challenges and limitations.

If you’re considering React for your next project:

React may not be perfect, but its flexibility, community, and ongoing evolution make it a reliable choice for building modern web applications.

References