React Core Concepts Flashcards

Learn the core concepts of React

1
Q

Components

A

Components are like building blocks for your app.
Each component is a small, reusable piece of your user interface (UI), like a button or a form.

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

Functional Components

A

These are simple functions that return what the UI should look like.

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

Class Components

A

These are a bit more complex and used to be the main way to create components, but now we often use functional components.

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

JSX (JavaScript XML)

A

JSX is a special syntax that looks like HTML but is used in JavaScript. It makes it easier to create and understand the structure of your UI.

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

Props (Properties)

A

Props are inputs passed from a parent component to a child component. They are read-only and used to pass data or functions to components.

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

Props usage

A

Props allow components to be dynamic and flexible, as they can change based on the parent’s state or data.

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

State

A

State is an object that holds data that may change over time and affect how the component renders.

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

State usage

A

Each component can manage its own state (especially with theuseStatehook in functional components) and re-render when the state changes.

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

Hooks

A

Hooks are functions that allow you to manage state and side effects in functional components.

Introduced in React 16.8, they remove the need for class components in many cases.

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

useState

A

Manages local state in functional components.

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

useEffect

A

Handles side effects like data fetching or updating the DOM.

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

useContext

A

Accesses context values without passing props through every level of the tree.

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

useReducer

A

Manages complex state logic, similar to Redux’s reducer concept.

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

Common Hooks

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

Virtual DOM

A

The Virtual DOM is a lightweight copy of the real DOM.
React uses the Virtual DOM to keep track of changes and update only the parts of the actual DOM that need to be re-rendered.

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

Virtual DOM usage

A

This makes React applications more efficient by minimising direct DOM manipulation.

17
Q

Lifecycle Methods (in Class Components)

A

Lifecycle methods are special methods in class components that are called at specific points in a component’s life (e.g., when it is created, updated, or destroyed).

Note: With hooks likeuseEffect, lifecycle methods in functional components are often replaced.

18
Q

componentDidMount()

A

Runs after the component is first rendered.

19
Q

Examples of Lifecycle Methods

A
  • componentDidMount()
  • componentDidUpdate()
  • componentWillUnmount()
20
Q

componentDidUpdate()

A

Runs after the component updates.

21
Q

componentWillUnmount()

A

Runs just before the component is removed from the DOM.

22
Q

Context and its usage

A

Context allows you to pass data through the component tree without manually passing props down through each level.
It is useful for global data like user authentication status or theme.

You useReact.createContext()to create a context, and components can access it with theuseContexthook or by subscribing to it.

23
Q

Conditional Rendering

A

Conditional rendering refers to rendering different components or UI elements based on certain conditions (e.g., whether a user is logged in).

24
Q

Conditional Rendering usage

A

This is typically achieved using JavaScript’s ternary operators or logical operators directly within JSX.

25
Q

Lists and Keys

A

When rendering lists of data in React, each list item should have a unique “key” prop. This helps React track which items have changed, been added, or removed, improving performance.

26
Q

Lists and Keys usage

A

Amap()function is commonly used to render lists in React, with each element given a unique key.

27
Q

Events

A

Events are actions that happen in the app, like clicking a button or typing in a field. You can attach functions to these events to run specific code when they happen.

Event handling in React is similar to native JavaScript, but events are named using camelCase (onClick,onChange, etc.) and use JSX to pass the event handler function.

28
Q

Events usage

A

Event handlers are passed as props to elements, and the function can be used to update the component’s state.

29
Q

Lifting State Up

A

Lifting state up refers to moving shared state to the closest common ancestor of the components that need it. This allows multiple components to access and modify the same piece of state.

30
Q

Fragment and usage

A

React fragments let you group a list of children without adding extra nodes to the DOM. It helps in reducing unnecessary markup.

<> … </>or<React.Fragment> ... </React.Fragment>.