React Flashcards

1
Q

What is React and why is it used?

A

React is a JavaScript library developed by Facebook for building user interfaces, especially single-page applications. It excels in building reusable component-based UIs.

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

What is JSX?

A

JSX stands for JavaScript XML. It’s a syntax extension for JavaScript that allows you to write HTML-like code inside JavaScript. It gets transpiled to React.createElement() calls in the background.

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

How does React’s virtual DOM work?

A

The virtual DOM is an in-memory representation of the real DOM. When the state of an object changes, React creates a new virtual DOM and compares it with the old one (diffing). Then it updates the real DOM in the most efficient way possible.

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

What are props and state in React?

A

Props (short for “properties”) are a way of passing data from parent to child components. They are read-only.
State is data that a component maintains and can change over time. Changes in state trigger a re-render of the component.

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

What are React Hooks?

A

Hooks are functions that let you use state and other React features without writing a class. Common hooks include useState, useEffect, and useContext.

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

Explain the lifecycle methods in class components.

A

Lifecycle methods are special methods that automatically get called as your component achieves certain milestones. Key methods include componentDidMount, shouldComponentUpdate, and componentWillUnmount.

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

How do you handle events in React?

A

In React, you handle events using camelCase, not lowercase. With JSX you pass a function as the event handler, rather than a string.

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

What is context in React?

A

Context provides a way to pass data through the component tree without having to pass props down manually at every level. Useful when certain props (e.g., locale preference, theme) are required by many components.

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

Explain the difference between a class component and a functional component.

A

In a functional component you can use state hooks to pass around data whereas in class you need to use props. In a functional component you can use useEffect for mounting versus having to use multiple mount functions like in class components.

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