React.js fundamentals Flashcards

1
Q

What is JSX in React?

A

JSX is a JavaScript Extension Syntax used in React to easily write HTML and JavaScript together.

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

How does the browser handle JSX code, and what tool can you use to make it work?

A

The browser doesn’t understand JSX because it’s not valid JavaScript. To make it work, JSX code needs to be transpiled using tools like Babel, which converts JSX into regular JavaScript code.

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

What does JSX code get converted to by Babel?

A

JSX code gets converted into a series of React.createElement calls, which are JavaScript function calls that create and describe React elements.

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

What is the syntax of React.createElement?

A

React.createElement(type, [props], […children])

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

Why was React.Fragment introduced in React 16.2?

A

React.Fragment was introduced to allow developers to group multiple adjacent JSX elements without adding extra DOM nodes to the structure. This helps avoid unnecessary div tags or other wrappers.

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

How can you add comments in JSX?

A

You can add comments in JSX using {/* /} inside curly braces, like this: {/ This is some text*/}.

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

Can you include JavaScript code within JSX? If so, how?

A

Yes, you can include JavaScript code within JSX by placing it inside curly braces { }. You can only use expressions that evaluate to a value, known as JSX Expression Syntax.

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

Which values are not displayed on the UI when used inside JSX?

A

Undefined, null, and boolean values are not displayed on the UI when used inside JSX, as they are treated as if they were not there

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

Why is className used instead of class for adding a class attribute in JSX?

A

className is used in JSX instead of class because class is a reserved keyword in JavaScript. Accessing props.class would result in an error.

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

In React, how are attribute names typically written?

A

In React, attribute names are typically written in camelCase, such as onClick instead of onclick.

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

X define the structure and behavior of parts of the user interface. They encapsulate reusable pieces of UI, making it easier to manage and render complex interfaces. What is X?

A

React components

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

What is the primary purpose of React DOM?

A

The primary purpose of React DOM is to render React components into the Document Object Model (DOM) of a web page. This allows developers to interact with and manipulate the web page’s structure and content.

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

What are controlled components in React, and why are they used?

A

Controlled components are React components that manage form elements and their corresponding data by synchronizing the component’s state with user input. They are used to ensure that React controls the input’s value based on the component’s state.

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

What are the key characteristics (3) of controlled components in React?

A
  1. state control
  2. event handling (e.g., onChange)
  3. maintaining a single source of truth for input values.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the concept of “lifting state up” in React?

A

In React, “lifting state up” refers to the practice of removing state from multiple components and moving it to their closest common parent. This allows you to manage the state centrally and pass it down to child components via props.

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

How by using „key„ you can reset the state of a component in React?

A

By changing the key prop of an element. This effectively tells React that it’s a different element, causing it to unmount the previous instance and remount the new one.

17
Q

What is the advantage of using useReducer with a reducer function in React?

A

Using useReducer with a reducer function provides a more structured and organized way to manage state updates in React components, especially when state management requirements become more complex.

18
Q

How does React allow a parent component to make information available to any component in the tree below it without passing it explicitly through props?

A

React allows a parent component to share information with any component in the tree below it by using “context.” Context provides a way to pass data implicitly to descendant components, avoiding the need to pass it explicitly through props.

19
Q

What is the purpose of state in React components?

A

The purpose of state in React components is to represent data that can change over time and influence the behavior and rendering of the component.

20
Q

What is the main purpose of React hooks?

A

The main purpose of React hooks is to enable the use of state and other React features in functional components, simplifying state management and side effect handling.

21
Q

Where can you use hooks in React?

A

Hooks can be used only in functional components and must be used at the top level of the component.

22
Q

What is a characteristic feature of functions that are considered hooks in React?

A

Functions that are considered hooks in React start with the prefix use, such as useState and useEffect.

23
Q

What does the Effect Hook do in React?

A

The Effect Hook, as the name suggests, performs an effect each time there is a state change in the component.

24
Q

When does the useEffect hook run in React?

A

The useEffect hook runs when the state changes. You can also specify dependencies, and it will run only when those dependencies change. For example, useEffect(() => {}, [count]) will run the effect only when the count state changes.