React Flashcards

1
Q

What is React?

A

a program that enables us to create an interactive UI

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

What is a React element?

A

an object that describes what the dom looks like

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

Interview Question!

difference between library and framework:

A

a framework will run the function for you when the time is ready.
a library will have a list of functions that you can use when you want

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

What is JSX?

A

it is a syntax extension to JavaScript. It is typically used with React to describe what the UI should look like. JSX produces React “elements” and can render them
Stands for JavaScript Syntax

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

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

A

because JSX cannot be read by the browser

React objects must be imported because it used in the final code that babel outputs

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

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

A

installing the dev-dependencies webpack, webpack-cli, babel-loader, @babel/core, @babel/plugin-transform-react-jsx, add a build script to run webpack in package.json. Then finally npm run build

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

What is a React component?

A

Conceptually, components are like JavaScript functions. They accept arbitrary 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
9
Q

How do you define a function component in React?

A

same way you define a function in javascript. however the name of the function has to start with a capital letter

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

How do you mount a component to the DOM?

A

ReactDOM.render(
react element,
element in the DOM
)

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

What are props in React?

A

the parameter of components (functions)
When React sees an element representing a user-defined component, it passes JSX attributes and children to this component as a single object. We call this object “props”.

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

How do you pass props to a component?

A

using props as an argument in the function/component and pass props as a javascript expression in the function definition

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

How do you write JavaScript expressions in JSX?

A

by using {} within JSX

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

How do you create “class” component in React?

A

class CustomButton extends React.Component

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
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
16
Q

What is the purpose of state in React?

A

represent the current situation of a component

setState() allows you to replace the state and render() will return a new react element

17
Q

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

A

button onClick = {function()}

18
Q

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

A

map method

19
Q

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

A

it needs to unique among all the elements in the array

20
Q

What are controlled components?

A

An input form element whose value is controlled by React

21
Q

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

A
onChange = {function}
value = {this.state.whateverthepropis}
22
Q

When does React call a component’s componentDidMount method?

A

after the render method

23
Q

Name three React.Component lifecycle methods.

A

constructor()
render()
componentWillUnmount()

24
Q

How do you pass data to a child component?

A

using prop