Summary and Key Takeaways
- React is a library, though it's actually a combination of two main packages:
react
andreact-dom
. - Though it is possible to build non-trivial user interfaces without React, simply using vanilla JavaScript to do so can be cumbersome, error-prone, and hard to maintain.
- React simplifies the creation of complex user interfaces by providing a declarative way to define the desired end state(s) of the UI.
- Declarative means that you define the target user interface content and structure, combined with different states (e.g., "is a modal open or closed?"), and you leave it up to React to figure out the appropriate DOM instructions.
- The react package itself derives UI states and manages a virtual DOM. It's "bridges" like
react-dom
orreact-native
that translate this virtual DOM into actual UI (DOM) instructions. - With React, you can build Single Page Applications (SPAs), meaning that React is used to control the entire user interface on all pages as well as the routing between pages.
- React projects can be created with help of the
create-react-app
package, which provides a readily configured project folder and a live preview development server.
What's Next?
At this point, you should have a basic understanding of what React is and why you might consider using it, especially for building non-trivial user interfaces. You learned how to create new React projects with create-react-app, and you are now ready to dive deeper into React and the actual key features it offers.
In the next chapter, you will learn about a concept called components which are the fundamental building blocks of React apps. You will learn how components are used to compose user interfaces and why those components are needed in the first place. The next chapter will also dive deeper into JSX and explore how it is transformed to regular JavaScript code and which kind of code you could write alternatively to JSX.
Test Your Knowledge!
Test your knowledge about the concepts covered in this chapter by answering the below questions. You can then compare your answers to example answers that can be found here: https://packt.link/ENPda.
- What is React?
- Which advantage does React offer over vanilla JavaScript projects?
- What's the difference between imperative and declarative code?
- What is a Single-Page-Application (SPA)?
- How can you create new React projects and why do you need such a more complex project setup?