React Flashcards

1
Q

What is React?

A

React is a declarative, efficient, and flexible JavaScript library for building 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

plain objects that describe what you want to see on the screen.

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(element, container)

Using the ReactDOM.render( ) method:

ReactDOM.render(element, container[, callback])

ReactDOM.render( ) method takes a JSX expression, creates a corresponding tree of DOM nodes, and adds that tree to the DOM

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

What is JSX?

A

JSX is a syntax extension to JavaScript that produces React “elements”
A nice and readable way of creating elements in React

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

You need to import react and react-dom in order to create DOM elements in React

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 a babel-loader along with a babel plugin to convert JSX

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

What is a React component?

A

Pieces of reusable code
Components are like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen.

independent and reusable bits of code.
They serve the same purpose as JavaScript functions, but work in isolation and return HTML.

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

The simplest way to define a component is to write a JavaScript function.
You can also use an ES6 class to define a component.

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

Using ReactDOM.render( ) method - use the function name as the type

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

props as a parameter in your function/class

Add the prop to your JSX like you would add an attribute to an HTML tag

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

Begin with the class keyword followed by the className followed by extends React.Component and you must define the render( ) method.

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

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 contain data or information about the component. A component’s state can change over time; whenever it changes, the component re-renders
To store data that could be prone to change, and if it does change, trigger the render() method to update the DOM.
to control what you want the user to see on the webpage
To indicate a component’s current status*

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

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

A

By assigning it to a prop on the react element - the prop starts with on & is in camelCase - the event handler is in camelCase.

As props to child components
as an attribute

17
Q

What are controlled components?

A

An input form element whose value is controlled by state

18
Q

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

A

value and onChange / handleSubmit and handleChange

19
Q

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

A

map ( ) method

20
Q

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

A

id or anything unique

21
Q

When does React call a component’s componentDidMount method?

A

After render, but before page is finished loading

22
Q

Name three React.Component lifecycle methods.

A
  1. componentDidMount() - gets called right after first render
  2. componentDidUpdate() - is given previous state & previous props. If state changes, this will be called once it has already been changed
  3. componentWillUnmount() - called right before the component is removed from the DOM

constructor, render, componentDidMount

23
Q

How do you pass data to a child component?

A

as a prop to the child component