React.js Flashcards

1
Q

What is React and it’s key features?

A

A javascript library for building user interfaces.

Key features: virtual DOM, reusable components, unidirectional data flow

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

What is the React Virtual DOM and how does it work?

A

A virtual representation of a UI that is kept in memory after the initial render

Any changes are first made to the virtual DOM, then synchronized with the ‘real’ DOM in an efficient way (reconciliation)

Improves performance by only updating the parts that have changed

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

Describe unidirectional data flow

A

Data has a single, clear direction of movement throughout the application.

Ensures a predictable and easier-to-understand flow of data, making the application more maintainable and less prone to bugs.

Data Down - data is passed from parent to child

Action up - child doesn’t directly modify the state of its parent; instead, it informs the parent about the desired change

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

Explain JSX syntax

A

JSX is a syntax extension for javascript, allowing XML code

Facilitates the creation of react elements in a concise and readable manner

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

How does React handle data binding?

A

React uses one-way data binding - where any changes to the data trigger re-renders

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

What are React props?

A

Properties - inputs to components, allowing the passing of data from parent to child

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

Explain state in React

A

An internal data storage mechanism in React components, when the state changes the component re-renders

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

Why use key attribute in React lists?

A

Facilitates efficient updates by identifying which items have changed, been added, or removed.

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

Controlled vs Uncontrolled

A

Controlled
* state is controlled by react
* Using useState to manage an input value in order to do something else with it

Uncontrolled
* state is managed by the DOM
*Using useRef to track an input value but doing nothing with it in state

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

Significance of React Hooks?

A

Functions (built-in or custom) that allow functional components to use state and lifecycle features

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

Describe some built-in React Hooks

A

useState - manage local state.

useEffect - side effects like data fetching, subscriptions, or manually changing the DOM

useMemo - prevents unnecessary recalculations in functional components.

useContext - consume values from the React context without wrapping the component in a context consumer

useReducer - alternative to useState for managing more complex state logic. It is particularly useful when the next state depends on the previous state.

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

Explain the lifecycle method in a React component

A
  1. Mounting - component is created & inserted into the DOM
  2. Updating - component is re-rendered as a result of changes in props or state
  3. Unmounting - component is being removed from the DOM
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Purpose of React Router?

A

Simplifies navigation in single-page applications by providing a set of components and hooks to manage routing and rendering based on the current URL

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

What is Redux?

A

State management library for larger JS applications

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

What is React Context?

A

Provides a way to pass data through the component tree without having to pass props manually at every level

Commonly used with themes, user authentication status, or any other global state across a React component tree

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

Explain HOC - Higher Order Components

A

Functions that take a component and return a new component with enhanced features, enabling code reuse and logic sharing

17
Q

How does Error Handling work in React

A

Error boundaries catch JS errors anywhere in the component tree using the componentDidCatch method

18
Q

What are Fragments in React?

A

Used to group multiple elements without introducing an additional parent element to the DOM

<></> uses empty angle brackets

19
Q

Explain reconciliation in React?

A

The process by which React updates the DOM to match the virtual DOM efficiently

20
Q

Explain how PropTypes work

A

Enforces the type of props passed to a component, providing runtime validation and documentation

21
Q

What are Portals?

A

Allow rendering children into a DOM element that exists outside of the parent component

22
Q

Function vs Class Components

A

Function - simple, stateless components introduced in React 16.8

Class - traditional, ES6 classes with state and lifecycle methods

23
Q

Explain Memoization

A

Optimizing expensive function components by caching the result of a computation based on it’s inputs

For example, when displaying text to the user as they type into an input

24
Q

How does Event Handling work

A

Attach event handlers using camelCase naming conventions (like onClick and onChange)

Treated as functions, allowing you to pass additional parameters and define custom behavior

25
Q

How does React handle Forms and Controlled components?

A

Controlled components manage form state through state, and update the UI based on changes in the components state

26
Q

Explain code-splitting

A

Breaking down a large chunk of JS code into smaller chunks and loading them on demand to enhance performance

27
Q

Explain how Server-Side Rendering works

A

The browser sends a request to the server, which executes the component code, creating a virtual DOM, and generating HTML

The fully rendered HTML is sent back to the client

Pros: Improves performance, SEO friendly
Cons: State management, Increased server load

28
Q

What are React Hook rules and why are they important?

A
  1. Only call them at the top level of functional components
  2. Do not use them inside loops or conditions.

Following these rules ensures the correct behavior of Hooks

29
Q

What is React Flow?

A

Flow allows us to add type annotations to our code, specifying the types of variables, function arguments, and return values.

This helps catch type-related errors early in the development process before the code is even run.

30
Q

How does React handle XXS (Cross-Site Scripting)

A

By using JSX to render content securely, preventing injection attacks by automatically escaping values before rendering.

31
Q
A