Thinking In React Flashcards

1
Q

What is Step 1 in Thinking in React?

A

Break the UI into a component hierarchy

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

How should you approach breaking the UI into a component hierarchy?

A
  1. Draw boxes around every component and subcomponent in the mock you got from the designer
  2. SRP (single responsibility principle): A component should ideally do just one thing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the two types of “model” data in React?

A
  1. props (i.e., properties)
  2. state
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What data type are both props and state in React?

A

Plain JavaScript objects

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

What is the primary difference between props and state in React?

A

Props get passed into a component (analogous to a function parameter)
while state is managed within the component only

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

What does it mean to say that props and state are deterministic in React?

A

The component should generate the exact same output given the same combination of props and state. If the component generates different output (given the above) something is broken.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  • *When should you use state**
  • *instead of a prop?**
A

If you will ever need to alter a component attribute at some point in time,
it should definitely go into the component’s state

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

What is a stateless component?

A

The component has props but no state.

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

What is a stateful component?

A

Both props and state; also known as state managers.

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

How do React achieve interactivity in components? Or, how can you trigger changes to your underlying data model?

A

With state

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

What three questions should one ask to determine if a piece of data should be in the component’s state?

A
  1. Is it passed in from a parent via props? (If so, it’s probably not state-worthy)
  2. Does it remain unchanged over time? (If so, it probably isn’t state)
  3. Can you compute it based on any other state or props in your component? If you can, it’s not state
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  • *What is the direction of**
  • *data flow in React?**
A

React is all about one-way data flow down the component hierarchy.

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

Where should your state live in the context of multiple nested components?

A

It should live in a parent component that lives above all other components that require that state. If you can’t find a parent in which it makes sense to store the state, you may want to create a new component purely for holding the state.

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

What is JSX?

A

A syntax extension to JavaScript

An HTML proxy in JavaScript

JavaScript & XML

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

What does JSX do?

A

JSX produces React “elements.”

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

Is using JSX required?

A

No, it’s not. But it is a useful abstraction providing a visual aid for developers.

It also allows React to show more useful error and warning messages.

17
Q

What is allowed inside curly braces (“{ }”) when working with JSX?

A

You can put any valid JavaScript expression inside the curly braces in JSX.

18
Q

How does React prevent injection attacks?

A

By default, React DOM escapes any values embedded in JSX before rendering them. Thus it ensures that you can never inject anything that’s not explicitly written in your application. Everything is converted to a string before being rendered. This helps prevent XSS (cross-site-scripting) attacks.