课程: Learning Full-Stack JavaScript Development: MongoDB, Node, and React
Why React?
- [Instructor] React is a JavaScript library that's entirely focused on one task, building user interfaces. It follows the Unix philosophy of doing one thing and doing it well. The React Library comes into packages, React and ReactDOM. And when we talk about React, we generally mean both of these packages, but it helps to understand the difference between them and how they work together. We use the React API to describe a user interface and the ReactDOM API to build that interface in the browser. These two packages are designed to work together. React is the what and ReactDOM is the how. And we the developers deal mostly with the what. Using the React language, we can tell ReactDOM what we want and ReactDOM takes our UI descriptions and figures out how to efficiently create them in a browser and how to update them as well when things get changed. The update process is actually what's more impressive about React. For that, React uses a programming concept known as the Virtual DOM to minimize Real DOM updates. The big picture of this Virtual DOM concept is that every time React creates an HTML tree in a browser, it keeps a copy of that tree in memory. Then when the app state changes and things need to change in the browser, React computes the new HTML version in memory first then it compares it with the current in browser HTML since that was kept in memory too. And this allows React to figure out what exactly has changed before making any actual changes in the browser. And then React only makes the changes that are needed, leaving everything else in the app as is. You don't actually need to fully understand that in order to use React, but understanding it would certainly make you write better React code. In this article, I go over this concept and many others in detail. We're going to cover some of the other concepts in this article over the next few videos, but it would be great if you can give this article a quick read at this point in the course if you can.