Why do frontend frameworks exist?

Aman VermaAman Verma
2 min read

While taking a course on React.js, I came across an interesting concept:

Why do frontend frameworks even exist?

The answer is quite interesting. In the early days of web, webpages were rendered entirely on server. You would have the data and the views/templates defined on the server. A webpage would be rendered by passing in the data to the view.

However, as web applications became more interactive, and as a result, implementing more JavaScript, this traditional approach started showing limitations, especially in terms of updating DOM.

Updating a section of webpage meant:

  • Traversing the entire DOM to find the relevant element

  • Manually updating it with javascript

  • Then setting the target element equal to the updated state

All of which was way too manual. Oftentimes you would be manipulating the state ( data ) in memory itself which could be accessed and directly modified from different parts of the application, hence introducing a lot of bugs.

Then came in React!

As the javascript interaction increased on the client-end the pages had to be more dynamic and more responsive. JavaScript heavy apps gave birth to client-side rendering. Now:

  • The servers would still contain the data ( provided usually via APIs ),

  • The client side would contain the view

  • The data is then passed to the views which are then rendered accordingly and React ensures that the UI ( views ) are ๐—ถ๐—ป ๐˜€๐˜†๐—ป๐—ฐ with the data, basically ๐—ฟ๐—ฒ๐—ฎ๐—ฐ๐˜๐—ถ๐—ป๐—ด to the change in state

React uses a virtual DOM and a declarative approach making state management far more easy, efficient and predictable as compared to the traditional approach.

Another concept that ensures the predictability in the state is React's recommendation to create ๐—ฃ๐˜‚๐—ฟ๐—ฒ ๐—ฐ๐—ผ๐—บ๐—ฝ๐—ผ๐—ป๐—ฒ๐—ป๐˜๐˜€, which means that a component must produce the same output for the same input everytime it is used. Or it should only return its own JSX.

Also with ๐—ก๐—ฒ๐˜…๐˜.๐—ท๐˜€ we have come a full circle to supporting server-side rendering again with server-components, but in a more optimised way and with the flexibility to choose between client side rendered components vs server-side rendered component using just a simple "use client" directive.

Frontend frameworks exist to bridge the gap between dynamic UIs and complex state management while keeping everything in sync and performant.

0
Subscribe to my newsletter

Read articles from Aman Verma directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aman Verma
Aman Verma

Hi! I am a Front-end developer from India. I love creating beautiful products and working with the latest technologies. Learning something new every single day has been my goal for a very long time because there is a joy to learn something new and then be able to create something wonderful. One quote I try to abide by is - "Live as if you were to die tomorrow. Learn as if you were to live forever."