React Flashcards

1
Q

What is React?

A

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

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

using ReactDOM.render(elementMade, root DOM node)

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

the React library must always be in scope from your JSX code, since JSX compiles into calls to React.createElement

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

similar to JavaScript functions, 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
8
Q

How do you define a function component in React?

A
function Component (props) {
return <h1>Hello, {props.name}</h1> ;
}
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

use ReactDOM.render( react element created , root DOM node);

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

What are props in React?

A

properties used for passing data from one component to another

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

as key value pairs, example text=’this’

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 variables 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 Component extends React.Component {
render( ) {
return Example, {this.props.example}
   }
}
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

object that stores a component’s dynamic data and determines the component’s behavior

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

provide a listener when the element is initially rendered onClick={eventHandlerMethod}

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

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

18
Q

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

19
Q

What are controlled components?

A

an input form element whose input value is always driven by the React state

20
Q

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

A

value and onChange

21
Q

When does React call a component’s componentDidMount method?

A

immediately after render

22
Q

Name three React.Component lifecycle methods.

A

constructor( ), render ( ), componentDidMount( )

23
Q

How do you pass data to a child component?

A

using props

24
Q

List 3 major advantages of React.

A
  1. it increases the applications performance
  2. JSX increases code readability
  3. component reusability
25
What does unidirectional data flow mean?
the data should only flow in one direction for example from parent to children
26
What are 3 major features of using React?
1. it uses the virtual DOM 2. it uses server-side rendering 3. it follows uni-directional data flow
27
what is the virtual DOM?
a lightweight JavaScript object which originally is just the copy of the real DOM; React's render function creates a node tree out of the React components and updates the tree in response to mutations in the data model.
28
why can't browsers read JSX?
browsers can only read JavaScript objects and JSX is not a regular JS object; therefore must transform JSX using Babel and then passing it to the browser
29
what are the different phases of react component's lifecycle?
initial rendering, updating(responds to changes in state), unmounting
30
what is Redux?
an open-source JavaScript library for managing application state. It is most commonly used with libraries such as React or Angular for building user interfaces
31
Which hook returns a pair with the current state value and a function that lets you update it?
useState
32
______ are functions that let you "hook into" React state and lifecycle features from function components.
Hooks
33
T/F | Hooks don't work inside classes
True
34
Which hook adds the ability to perform side effects from a function component?
useEffect
35
Which hook serves the same purpose as componentDidMount, componentDidUpdate, and componentWillUnmount?
useEffect
36
A component calling _______ (hook) will always re-render when the context value change.
useContext
37
When should useContext be used?
to share data that can be considered global for a tree of react components
38
When using useContext what steps should be taken? (5)
1. import createContext 2. call createContext() save to a variable and export 3. context provider with a value attribute (top of tree) 4. import useContext (where context is needed) 5. call useContext(context argument)
39
What arguments are passed when calling useEffect ?
arrow function and optional array of dependencies
40
How do you pass data from child to parent?
1. Create a callback function in parent and empty state 2. Pass the function as a prop to the child component 3. Set the data using the useState hook.