React Fundamentals Flashcards

1
Q

What is React.js?

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

What is JSX?

A

JavaScript XM (JSX) is an HTML-like syntax extension for creating UI components, which will be compiled to JavaScript at runtime.

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

What are the 2 ways of creating a component?

A

Class-based and functional.

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

What is state?

A

A plain object that stores dynamic data that changes based on user activity.

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

What is a hook?

A

A special function (introduced in React 16.8) that lets you use state and other React features without writing a class.

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

In which direction does data flow?

A

Top-down (aka unidirectional) data flow.

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

What are props?

A

Inputs to components, using the HTML-like attributes structure.

E.g <Child mouth={food} />

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

What is the main difference between state and props?

A
  • Props get passed to the component similar to function parameters.
  • State is managed within the component similar to variables declared within a function.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are 3 ways events in React are handled differently from regular HTML?

A
  • Event attributes are in camelCase
  • Use event.preventDefault() to prevent default behavior
  • Functions are invoked without need for ()

E.g. <button onClick={submitForm}>Submit</button>

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

What is a component?

A

A self-contained, reusable piece of a user interface.

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

What are the three phases in the lifecycle of a component

A
  • Mounting: adding elements into the DOM
  • Updating: when a component’s state or props is changed
  • Unmounting: component is removed from the DOM
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are controlled and uncontrolled components?

A

Related to state management in forms.
* Controlled: form data is handled by a React component.
* Uncontrolled: form data is handled by the DOM itself.

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

What is a higher order component (HOC)?

A

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

E.g. const EnhancedComponent = higherOrderComponent(WrappedComponent)

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

What is the children prop?

A

Pass components as data to other components using the reservered children prop.

E.g. const List = ({children}) => <ul>{children}</ul>

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

What is a fragment?

A

Group a list of children without adding extra nodes to the DOM.

E.g. const Homepage = () => <><h1>My Title</h1><p>My paragraph</p></>

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

How are CSS classes added to a component?

A

Similar to HTML attributes but in camelCase.

E.g. <Navbar className="nav nav-black" />