React Flashcards

1
Q

What is the difference between React class components and functional components with hooks? If you were building a project, which one would you choose?

A

If the project didn’t hold a lot of complicated state, functional components are easier to think and reason about. more control then class components. The lifecycle events have corresponding react hooks. If using redux, I’d use class components.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the virtualDOM

A

Maintaining the representation of the UI in the code, then using the programming library to sync with the real DOM, react uses ReactDOM. Creating the UI and maintaining that state, for ex. I want a button to be green, holding that state in the code. ReactDOM will optimize this process by syncing that with the real DOM.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

One click calls 4 functions to setState(), will React go one by one and re-render or trigger all of the calls and just re-render once?

A

React will update in batch, updates all states into just 1 re-render

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which tools for global state management?

A

Redux - state management library where you create a state tree. Let’s say there’s a store object that maintains the entire state of the UI in that tree. If anything changes, I fire an event saying this changed, then there are reducers that make the necessary changes. Maintaining the entire state of an application in one object. Works well with React because it can use that state tree and render the UI.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Best practices in React?

A

Modularization, single responsibility principle with components, linter, using ES6 syntax, functional components over class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Code splitting?

A

Instead of loading entire application, only load what’s needed at startup and load others later when used, so webpack can manage it, faster loading, speed/performance/scalability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is new in React 18

A

concurrency, automatic batching, transitions, suspense on the server, useTransition, useDeferredValue, some hooks and APIs, createRoot, hydrateRoot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to upgrade React 17 app to React 18

A

first is to change the index.js file, previously there was reactDOM.render(), now it’s reactDOM.createRoot() then root.render()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is automatic batching?

A

Before React 18 there was some batching, but it didn’t batch something like setState(), automatic batching runs now in operations like event handlers and promises automatically.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are transitions and how are they diff from bouncing or setTimeOut()?

A

takes a very heavy operation and reserves it to a lower priority queue so it doesn’t freeze the screen. For ex., if an operation takes too long to execute, previously react would freeze the screen until the operation was complete, now, with transitions it executes when it’s ready, part by part. Diff from setTimeOut() because you cannot set a time on transitions and it’s not executed all at once

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is suspense on the server?

A

It’s like server-side rendering. Content is loaded on the server and then sent to the client. All components don’t need to be rendered at the same time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly