React interview Flashcards

Common tech questions for react/typescript positions (32 cards)

1
Q

What is React?

A

A JavaScript library for building user interfaces.

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

True or False: React uses a virtual DOM.

A

True

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

What are components in React?

A

Reusable pieces of UI that can be defined as classes or functions.

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

Fill in the blank: In React, a component’s state is managed using the ______ hook.

A

useState

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

What is JSX?

A

A syntax extension for JavaScript that looks similar to XML or HTML.

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

What is the purpose of the useEffect hook?

A

To perform side effects in function components.

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

What does props stand for in React?

A

Properties, which are used to pass data from parent to child components.

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

True or False: React components must return a single root element.

A

True

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

What is the difference between state and props?

A

State is managed within a component, while props are passed from parent to child components.

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

What is a higher-order component (HOC)?

A

A function that takes a component and returns a new component.

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

Fill in the blank: In React, the ______ method is used to update the component’s state.

A

setState

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

What is the purpose of the React Router?

A

To enable navigation between different components in a React application.

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

What are controlled components in React?

A

Components that derive their form data from the component’s state.

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

What is TypeScript?

A

A superset of JavaScript that adds static type definitions.

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

True or False: TypeScript can be used with React applications.

A

True

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

What is the purpose of interfaces in TypeScript?

A

To define the shape of an object.

17
Q

What does the ‘any’ type in TypeScript signify?

A

It allows a variable to hold any type of value.

18
Q

Fill in the blank: In TypeScript, you can define a type using the ______ keyword.

19
Q

What is the use of the ‘key’ prop in React?

A

To uniquely identify elements in a list for efficient updates.

20
Q

What is the significance of the useRef hook?

A

It allows you to create mutable references to DOM elements.

21
Q

What is the difference between class components and functional components?

A

Class components are ES6 classes, while functional components are plain JavaScript functions.

22
Q

True or False: React.StrictMode is used to highlight potential problems in an application.

23
Q

What is the purpose of the Context API in React?

A

To provide a way to pass data through the component tree without passing props manually at every level.

24
Q

Fill in the blank: You can manage global state in React using the ______ hook.

25
What is a React fragment?
A lightweight component that allows grouping of multiple elements without adding extra nodes to the DOM.
26
What is the purpose of the shouldComponentUpdate lifecycle method?
To determine whether a component should re-render.
27
What is the use of the useMemo hook?
To memoize expensive calculations and optimize performance.
28
What does the term 'lifting state up' mean in React?
Moving state to a common ancestor component to share it among child components.
29
What is the purpose of the useCallback hook?
To return a memoized callback function.
30
True or False: React only re-renders components that have changed.
True
31
What is the difference between useEffect and useLayoutEffect?
useLayoutEffect runs synchronously after all DOM mutations, while useEffect runs asynchronously after painting.
32
Fill in the blank: In TypeScript, you can enforce a type on a function parameter using ______ syntax.
functionName(param: type)