React and Typescript Flashcards

(50 cards)

1
Q

What is React?

A

A JavaScript library for building user interfaces using a component-based architecture.

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

What is a React component?

A

A reusable piece of UI defined as a function or class.

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

What are props in React?

A

Inputs passed from parent to child components to configure behavior or appearance.

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

What is state in React?

A

A component-specific object that determines how a component behaves and renders.

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 allows writing HTML-like code in React.

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

What is the virtual DOM?

A

A lightweight in-memory representation of the real DOM used to optimize rendering.

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

What is the useEffect hook?

A

A hook for handling side effects like data fetching or subscriptions.

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

What is the useState hook?

A

A hook that adds state management to functional components.

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

What is the purpose of React keys?

A

To help React identify which items changed, added, or removed in a list.

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

What is React Router?

A

A library for routing in React applications, enabling dynamic navigation.

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

What is the useRef hook?

A

A hook that provides a mutable reference that persists across renders.

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

What is the useCallback hook?

A

Returns a memoized version of a callback function.

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

What is the useMemo hook?

A

Memoizes the result of a computation to avoid unnecessary recalculations.

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

What is context in React?

A

A way to share data across components without using props.

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

What is the useContext hook?

A

Allows consuming context values in functional components.

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

What is a custom hook?

A

A reusable function that uses built-in hooks and starts with ‘use’.

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

What is a controlled component?

A

A component whose input form elements are controlled by state.

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

What is an uncontrolled component?

A

A component that manages its own internal state using refs.

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

What is React.memo?

A

A higher-order component that memoizes the result to prevent re-rendering.

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

What is the useReducer hook?

A

A hook for managing complex state logic with reducers.

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

What is TypeScript?

A

A superset of JavaScript that adds static typing.

22
Q

Why use TypeScript with React?

A

To catch errors during development, improve code clarity, and enable powerful IDE support.

23
Q

How do you type React props?

A

By defining an interface and passing it as a generic to the component.

24
Q

How do you type component state in TypeScript?

A

By using type annotations with useState or interfaces in class components.

25
What is a union type?
A type that allows one of several possible types (e.g., 'string | number').
26
What is a type alias?
A custom name for a type defined with the 'type' keyword.
27
What is an interface?
A way to define object shapes in TypeScript.
28
What are optional properties in TypeScript?
Properties with a '?' that are not required to be passed.
29
What is type inference?
TypeScript's ability to automatically determine a variable's type.
30
What are generics in TypeScript?
Reusable types that allow components or functions to work with any data type.
31
How do you type useState with a custom type?
useState(initialValue)
32
How do you type useRef with a DOM element?
useRef(null)
33
How do you type event handlers in React?
Use React types like React.ChangeEvent.
34
How do you type children in React components?
Use 'children: React.ReactNode' in the props interface.
35
How do you handle default props in TypeScript?
Set default values in destructuring or use default parameters.
36
How do you use enums in React with TypeScript?
Define an enum and use it as a prop or state type.
37
How do you type functional components?
Use FC or define props explicitly with generics.
38
What is React.FC?
A type for functional components that automatically includes children.
39
When should you avoid using React.FC?
When you want explicit control over props and children typing.
40
What is the difference between interface and type in TypeScript?
Both define object shapes; interfaces are extendable and preferred for public APIs.
41
What is the purpose of a tsconfig.json file?
It configures the behavior of the TypeScript compiler.
42
What is ESLint used for?
To analyze code for errors and enforce coding standards.
43
What is Prettier?
An opinionated code formatter for consistent code style.
44
What is Vite?
A fast frontend build tool that supports React and TypeScript with HMR.
45
What is Create React App?
A tool to bootstrap React projects with sensible defaults.
46
How do you install TypeScript in a React project?
Use 'npm install typescript @types/react @types/react-dom'.
47
What is React Testing Library?
A testing utility focused on testing components from the user's perspective.
48
What is the difference between shallow and full rendering in tests?
Shallow renders only the component, full rendering includes child components.
49
How do you handle form validation in React + TS?
Use form libraries like react-hook-form with typed schemas.
50
What is a discriminated union in TypeScript?
A union of object types that include a common literal property for type narrowing.