Basics Flashcards
What is “state”?
All the internal data that defines an application at a given point in time
What is React’s approach to reactive UI rendering?
You declare how state is represented as visual elements of the DOM. From then on, React automatically updates the DOM to reflect state changes.
What is React’s ‘raison d’etre’?
Reduce the complexity of creating/maintaining UIs
What are components?
Self-contained, concern-specific building blocks that are easy to reuse, extend and maintain.
Give 3 reasons why JSX is great for describing user interfaces?
1) it’s declarative
2) it’s easy to spot the relationship between elements
3) it’s easy to visualize the overall structure of your UI.
How did the web “used” to work?
For every interaction the user performed on a page, a whole new page was sent from the server (even if this new page was only a slightly different version of the page the user was on).
What does SPA stand for?
Single Page Application
What are SPAs constantly doing?
- Fetching new data
- transforming parts of the DOM as the user interacts through the UI
What does DOM stand for?
Document Object Model
What happens when interfaces grow more complex?
It gets more difficult to:
- examine the current state of the application
- make the necessary punctual changes on the DOM to update it
What technique do other JS frameworks use to keep the interface in sync with state?
Data binding
For performance reasons it’s not viable to trash and re-render the entire interface every time state changes. What’s React’s solution to this?
The ‘virtual DOM’ - an in-memory, lightweight representation of the DOM
What is the advantage of the virtual DOM over the real DOM?
It’s faster to manipulate than the real DOM
What are two typical things that might change the state of an application?
User interaction and data fetching
How does React use the virtual DOM?
- It quickly compares the current state of the UI with the desired state.
- It then computes the minimal set of real DOM mutations to achieve the change.
What is the ‘end benefit’ of React’s virtual DOM?
- It makes React very fast and efficient.
- React apps can easily run at 60 fps, even on mobile devices
What does ‘fps’ stand for?
Frames per second
What approach does developing applications using components allow us to take?
A “divide and conquer” approach, where no particular part needs to be especially complex
What is the advantage of being able to combine components?
We can create more complex and feature-rich components
React components are written in plain JS. What has traditionally been used for web application UIs though?
Templating languages and HTML directives
Why can templating languages be limiting?
They dictate the full set of abstractions that you are allowed to use to build your UI
What does React’s use of a full-featured programming language to render views make it easier to do?
Build abstractions
Why do React components lead to a separation of concerns?
They are self-contained, combining unifying markup with its corresponding view logic
What did separation of concerns ‘used to mean’?
HTML for content structure, CSS for styling and JS for behaviour