Introducing React Flashcards

1
Q

What are the key benefits of using React?

A

Component-based structure, efficient rendering with virtual DOM, minimized real DOM updates.

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

Why is updating the real DOM costly?

A

The real DOM update requires recalculating styles and layouts, which impacts performance.

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

What is JSX in React?

A

A syntax extension that looks like HTML but is transpiled into JavaScript.

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

Why does JSX use className instead of class?

A

class is a reserved keyword in JavaScript, so React uses className.

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

How do you embed JavaScript expressions in JSX?

A

By wrapping the expression inside {} (e.g., <h1>{title}</h1>).

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

What is the entry file of a React app?

A

index.js, where createRoot() initializes the React app.

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

What does StrictMode do in React?

A

Helps detect potential problems by logging warnings in the console.

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

What is the structure of a typical React component tree?

A

A hierarchy where the root component (e.g., App) contains nested components and elements.

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

What is the difference between a named export and a default export?

A

Named exports allow multiple exports from a module, while default exports export a single value.

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

How do you import a default export from a module?

A

import myFunc from './myModule'; (import name can be different).

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

How do you import named exports from a module?

A

import { myFunc1, myFunc2 } from './myModule'; (names must match).

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

What are props in React?

A

Props are an object used to pass data from a parent component to a child component.

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

How do you pass props to a React component?

A

Using JSX attributes: <Component propName="value" />.

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

What is state in React?

A

A special variable that holds component data and triggers re-rendering when updated.

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

How do you declare state in a functional component?

A

Using the useState hook: const [state, setState] = useState(initialState);.

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

How do you handle events in React?

A

By passing an event handler function to an element’s event prop: <button onClick={handleClick}>Click</button>.