Basics Flashcards
What is “state”?
All 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 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
What does SPA stand for?
Single Page Application
What are SPAs constantly doing?
1) Fetching new data
2) 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?
Becomes difficult to:
1) Examine the current state of the application
2) Make the necessary 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 is React’s solution to this?
The ‘Virtual DOM’ :
An in-memory, lightweight representation of the DOM
When to use a Class Component over a Function Component?
Class components
- the render() method will be called, whenever the state of the components changes.
- should be preferred whenever we have the requirement with the state of the component.
Functional components
- render the UI based on the props
- no render() method
What are props in React?
- Inputs to components
- They pass custom data to your component
- They trigger state changes
Why should we not update the state directly?
- If you try to do it directly, it won’t re-render the component
- use setState() method, it schedules an update to components state object which triggers the component to re-render
How to pass a parameter to an event handler or callback?
You can use an arrow function to wrap around an event handler and pass parameters:
this.handleClick(id)} />
This is an equivalent to calling .bind:
Apart from these two approaches, you can also pass arguments to a function which is defined as arrow function
handleClick = (id) => () => {
console.log(“Hello, your ticket number is”, id)
};