React - Basic Flashcards

1
Q

What are the key features of React.js?

A
  1. a virtual DOM for efficient rendering,
  2. component-based architecture,
  3. JSX syntax for defining components,
  4. and unidirectional data flow.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is unidirectional data flow in react?

A
  • Data flows only 1 way from parent to child using props
  • If a child needs to change the state it does so via a callback passed down by the parent.
  • Using the callback will update the parent components state and cause the parent and subsequent child components to re-render.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is JSX?

A

-A syntax extension for JavaScript that allows you to write HTML-like code within your JavaScript files.

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

Explain the concept of virtual DOM in React.js.

A

A lightweight copy of the real DOM which allows React to efficiently update and render only the necessary components when there are changes

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

What is a functional component

A

JavaScript functions that receive props as input and return JSX elements as output.

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

What are class components

A

Now are considered a little bit out dated compared to functional components. They extend the React.Component class and have the lifecycle methods.

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

What is the purpose of state in React?

A
  • State is used to store and manage data that can change over time within a component.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you update state in React?

A
  • You should never update state directly.
  • Functional components should use the useState react hook’s setter method to updated the state.
  • Class components should use the setState() method to update state.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are controlled components in React?

A
  • Where the values of form elements are controlled by React state.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the significance of keys in React lists?

A

Used to help React uniquely identify and differentiate between elements in an array of components.

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

What is React Router?

A
  • A popular routing library for React applications.
  • It allows you to define different routes and their corresponding components, enabling navigation and rendering different components based on the URL
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the purpose of the useEffect hook in React?

A
  • The useEffect hook is used to perform side effects in functional components such as making API calls.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the purpose of the useContext hook?

A
  • It provides a way to access values that are globally available to all components within a specific context.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the purpose of the useCallback hook?

A
  • Used to return memoized versions of functions in React so that a function is only reloaded when one of the useCallback dependencies has changed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the purpose of the useRef hook?

A

Allows you to create a mutable reference that persists across renders and doesn’t cause a re-render when it’s value changes.

It is commonly used to access or store DOM elements without triggering a re-render.

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

What is the significance of the Fragment component in React?

A
  • It is a built-in component provided by React.
  • It allows you to group multiple elements without adding an extra DOM element.
  • It helps in avoiding unnecessary wrappers in the component hierarchy.
17
Q

How can you optimize performance in React applications?

A
  1. Using key props correctly,
  2. implementing shouldComponentUpdate or React.memo / React.useCallback,
  3. code splitting using import with React.lazy (Lazy loading a component only when it’s needed),
  4. using production builds,
18
Q

Explain the concept of React Hooks.

A

Functions that make it possible to use state and handle side effects in Functional Components in place of Class Components.

19
Q

What is Redux?

A

A state management library for JavaScript applications. .

20
Q

What are React Portals?

A
  • Provide a way to render a component like a Modal in a different part of the DOM tree outside of the parent component’s hierarchy using the createPoral function that recieves the JSX that you’d like to render and the element that you’d like to be the parent of the JSX.
21
Q

How can you handle errors in React?

A

This is something that is easier to do with Class Components because functional components cannot capture errors during rendering.

You create something called an ErrorBoundary class that wraps a component and then use the getDerivedStateFromError and componentDidCatch lifecycle methods to essentially catch any errors that occure with that components hierarchy.

This limits the impact of those errors so that the whole application doesn’t fail.

22
Q

What are Higher-Order Components (HOCs) in React?

A

They take a component as a prop input, they wrap that component in reusable functionality and return it as a now enhanced component.

23
Q

How can you handle events in React?

A

attaching event handlers such as onClick, to JSX elements.

24
Q

How do “keys” help React to more efficiently render lists of components?

A

When the state or props change, react will compare the new list of keys to the old list and determine the differences so as to minimize unnecessary re-renders.

25
Q

How do “keys” help react to preserve component state?

A

They help react to understand which components have changed, been added or removed.