React Flashcards

1
Q

Do states persist when a component is re rendered?

A

Yes

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

What does it mean to “lift a state”?

A

Move a state to a parent component

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

When would it be practical to lift a state?

A

When a sibling component also needs access to that state.

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

Can props be passed from parent to child?

A

Yes

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

Can props be passed from child to parent?

A

No

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

Can props be passed from sibling to sibling?

A

No

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

How would you remove an item from an array stored in a state?

A

Use the filter function to create a new array that excludes the item

setItems((items) => items.filter(item => item.id !== id))

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

What is a controlled element?

A

An element that has it’s value defined by a state and also has an event handler which sets the state on change.

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

When would you need to use back ticks instead of quotations?

A

When you need to concat a variable and a string inside JSX {}

eg. <li className={pizza ${pizzaObject.soldOut ? "sold-out" : ""}}>

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

What is a derived state?

A

A normal variable that is using data from a state to calculate new data.

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

What is a children prop?

A

Children prop is the html content in between the opening and closing tag of a component. The component will receive this html as a prop called “children”.

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

What is a Structural component?

A

A component that contains other components and its purpose is to be the parent.

Examples would be pages, layouts, screens.

They can be large non reusable components but they don’t have to be.

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

What is a Stateless / Presentational component?

A

A component that has no state. It might receive and display props. It is usually small and reusable.

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

What is a Stateful component?

A

A component that has a state. Can be small and reusable.

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

What is prop drilling?

A

Passing a prop down to a component that is deeply nested. This means multiple components that don’t use the prop will need to receive it so they can pass it on to a child component until it reaches the component that will actually use the prop.

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

What is Component Composition?

A

Combining different components using the ‘children’ prop or explicitly defined props. This makes components more reusable because their content is not predefined.

17
Q

What is a Component?

A

Description of a piece of UI

A component is a function that returns react elements (element tree), usually written as JSX

“Blueprint” or “Template”

18
Q

What is a Component Instance?

A

Instances are created when we use components

It is a physical manifestation of a component

It is an individual copy of a component

Has its own state and props

Has a lifecycle

19
Q

What is a React Element?

A

JSX is converted to React.createElement() calls

A React element is the result of these function calls

Information necessary to generate DOM elements which are the final visual representation of component instances rendered in the browser

20
Q

Explain the uses and purposes of the “Key Prop”

A

?????????????

21
Q

Event Bubbling

A

lecture 136-138

22
Q

Thinking in react section 10

A

re do

23
Q

UseEffect

A

A function that should be used to implement side effect code. UseEffect will only run when the component is first mounted or when one of it’s dependencies is updated.

24
Q

What is a side-effect

A

An interaction between a React component and something outside the component.

25
Q

CleanUp

A

A function that can be returned from a useEffect function.

Runs before the effect is executed again.

Runs after a component is unmounted.

26
Q

do currency convertor l.158

A
27
Q

Rules of hooks

A

Only call hooks at the top level (not inside conditionals, loops, nested functions etc)

Can only be called from React functions

28
Q

useRef

A

Store a reference that will persist across renders.

A variable that persists across renders but is not suitable for useState.

Selecting and storing DOM elements.

29
Q

Differences between useState and useRef

A

Updating ref does not trigger a re-render like state does.

A ref is mutable while state is immutable.

States update asynchronously while refs do not.