React Flashcards

1
Q

What are the 3 rules of JSX?

A
  1. Return a single root element.
  2. Close all the tags, including self-closing tags (< />).
  3. camelCase most things.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why do multiple JSX tags need to be wrapped with a parent element?

A

JSX is JavaScript - even though it looks like HTML - and a function in JavaScript cannot return two objects without wrapping them into an array.

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

What is a React Fragment?

A

A special React element that can be used to wrap multiple JSX elements without actually adding an extra element into the DOM.

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

Why are JSX attributes written in camelCase?

A

Because they are converted into keys of JavaScript objects and those keys/variables cannot contain dashes (so ‘stroke-width’ becomes ‘strokeWidth’).

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

Why is the attribute ‘className’ used in React?

A

Because ‘class’ is a reserved JavaScript keyword.

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

Why do you need to compile your React code?

A

Because React used JSX which needs to be compiled into plain JavaScript.

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

What is a React component?

A

JavaScript functions that accept input - called ‘props’ - and return UI/HTML/JSX elements.

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

What is the naming convention for React components?

A

Components should start with a capital letter to distinguish them from plain HTML and JavaScript.

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

What are props?

A

Data passed to components as custom arguments/attributes that change the component’s behavior, look or what is rendered.

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

What data type are props?

A

Object

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

How are JavaScript variables used inside JSX markup?

A

By using the curly braces ‘{ }’ syntax.

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

What are the 4 JavaScript expressions that can be added inside JSX curly braces ‘{ }’ ?

A
  1. Object property with dot notation
    <h1>{props.title}</h1>
  2. Template literal
    <h1>{Cool ${title}}</h1>
  3. Returned value of a function
    <h1>{Cool ${title}}</h1>
  4. Ternary operator
    <h1>{title ? title : ‘Default Title’}</h1>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What prop should each child in a list have?

A

A “key” prop

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

Why are “key” props necessary for all list items in React?

A

Because they uniquely identify the items in an array so that React knows what elements to update in the array.

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

What are props used for?

A

To pass information to components

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

What event listener is used for input fields?

A

onChange

17
Q

What event listener is used for forms?

A

onSubmit

18
Q

What are hooks?

A

Special functions that let you “hook into” React features such as adding state to function components.