React Flashcards

1
Q

What is React?

A
  • a JavaScript library for creating user interfaces
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a React element?

A
  • a plain object that describes what the DOM should look like
  • (tells you tagName, props, children)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you mount a React element to the DOM?

A
  • ReactDOM.render( )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is JSX?

A
  • a syntax extension to JavaScript that produces React elements
  • basically, JSX just provides “syntactic sugar” for the React.createElement( ) method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why must the React object be imported when authoring JSX in a Module?

A
  • The React library must always be in scope from JSX code since JSX compiles into calls to React.createElement( ).
  • because it is used in the final code that Babel outputs.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can you make Weback and Babel work together to convert JSX into valid JavaScript?

A
  • install the Webpack and Babel devDependencies
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a React component?

A
  • Components let you split up the UI into independent, reusable pieces, and think about each piece in isolation.
  • Conceptually, they are like JavaScript functions/classes. They accept inputs (called props) and return React elements describing what should appear on the screen.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you define a function component in React?

A
  • using a JavaScript function or class - needs a capitalized Name and needs to return a React element
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you mount a component to the DOM?

A

using ReactDOM.render( )

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

What are props in React?

A
  • properties of an object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you pass props to a component?

A
  • make a React element with the type, and then pass the prop using key=value pairs ( =’ ‘ or ={ } )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you write JavaScript expressions in JSX?

A
  • using curly braces around the expressions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you create a “Class” component in React?

A
  • class ClassName extends React.Component { }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you access props in a class component?

A
  • using the props property of the this object

- this.props.’prop’

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

What is the purpose of state in React?

A
  • to represent the current state of the component

- the values you put in state change over time, in event handlers, you update state using setState( )

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

How do you pass an event handler to a React element?

A
  • you provide a listener when the element is initially rendered
  • add an event listener as a prop on the element and set a JavaScript expression { } with a function/event-handler
17
Q

What Array method is commonly used to create a list of React elements?

A

.map( )

18
Q

What is the best value to use as a “key” prop when rendering lists?

A
  • a string that uniquely identifies a list item among its siblings ( most often you’d use id’s from your data as keys)
19
Q

What are controlled components?

A
  • an input form element whose value is controlled by React (by making the React state be the “single source of truth”)
20
Q

What two props must you pass to an input form for it to be “controlled” ?

A
  • onChange and the value prop