React Flashcards

1
Q

What is JSX?

A

JavaScript XML that makes it easier to write and add HTML in react so that we can visually see the UI design in js code.

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

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

A

because JSX compiles into calls to React.createElement. that is why we need to import React library. (must be in scope).
createElement –> method of the React object.

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

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

A

with plug in ‘@babel/plugin-transform-react-jsx’

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

What is a React component?

A

a piece of a UI or feature of the webpage. It allows you to split the UI into dependent, reusable pieces.
–> Think about it as a function!!!

has to return a react element (Source: Lecture)

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

How do you define a function component in React?

A
function Capital first letter of the function definition.
Write a javascript function that returns a react element!!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
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
7
Q

What are props in React?

A

object that is used to pass data between react

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

How do you pass props to a component?

A

state the component name and key and value. (props.name).

key value pairs (looks like an attribute in html but its not)

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

How do you write JavaScript expressions in JSX?

A

inside curly braces.

example: { props.text }

OR { props.text.toUpperCase() }

Source: Lecture

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

What is the purpose of state in React?

A

Determine what is going to be displayed on the screen and also for reusability. (object that can change).

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

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

A

name of the event ={} –> name of the attributes.

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

What are controlled components?

A

input form whose value is controlled by React

react state is the source of truth

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

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

A

handleSubmit and handleChange!

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