React Flashcards

1
Q

What is React?

A

A JavaScript library for building user interfaces or UI components

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

What is a React element?

A

React element is something that describes DOM nodes and properties virtually

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

root.render(element)

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”

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

Because the React library must be in scope from the JSX code in order to make calls to React.createElement

So the JSX can be converted into valid JavaScript that a browser can understand.

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

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

A

using babel loader with plugin @babel/plugin-transform-react-jsx

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

What is a React component?

A

a JavaScript class or function that optionally accepts inputs i.e. properties(props) and returns a React element that describes how a section of the UI (User Interface) should appear.

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

By writing a JavaScript function that accepts props as a single argument and returns 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

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

They are objects used to pass data between react components

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

<Component>
</Component>

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

wrap it in { } curly braces

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

How do you create “class” component in React?

A

class ComponentName extends React.Component {
render ( ) {
return….
}
}

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

this.props

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

State is an object where property values belonging to a component are stored. When state changes, the component re-renders

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

as an attribute with a function

17
Q

What are controlled components?

A

An input form element whose value is controlled by React is called a “controlled component”.

18
Q

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

A

value and onChange.

19
Q

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

A

map()

20
Q

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

A