w6d5 - react Flashcards

1
Q

How do you increase the state of something managed by React by 1?

A

this.setState( { someProperty: this.state.someProperty + 1 } )

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

How does interpolation work in JSX?

A

{ variable }

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

How would you render a simple button in JSX?

A

render ( ) {

return ( <button> )</button>

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

How do you set up React’s entry point into HTML?

A

Add a listener for DOMContentLoaded that:

  1. locates an existing root element to insert code into via document.getElementById(‘root’)
  2. runs ReactDOM.render( <SomeReactComponent></SomeReactComponent>, rootElement)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In order to show our actual .js files in chrome debugger, rather then the bundled .js files, what do we add to webpack.config.js ?

A

devloot: ‘source-map’

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

What are some of the React lifecycle methods?

A
componentWillMount
componentDidMount
componentWillReceiveProps
componentWillUpdate
componentDidUpdate
componentWillUnmount
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you install something with npm and make a record of it in your config file?

A

npm install –save <package_name></package_name>

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

What are the resultant values of this destructuring operation:

const { a: x, b: y } = { a: 1, b: 2 }

A

x === 1

y === 2

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

Show code that will export a function (that does nothing) ES6-style

A

export const someFunc = ( ) => { };

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

How does ES6’s import syntax work?

A

import ClassName from ‘./source_file’

note the lack of .js

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

How do you import multiple items ES6-style?

A

import { item1, item2, … } from ‘./source_file’

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

JS: How can you check the types of things passed in as arguments?

A

typeof – for primitives

arg instanceof SomeClass – for things that are typeof “object”

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

React.createElement takes what parameters?

A

type: ‘div’, ‘span’, etc, or a React.Component

[props],
[…children]

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

How do you pass a function as the first param to ReactDOM.render( ) ?

A
  • Make sure the function is ProudCased

- Pass it wrapped in < /> brackets

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

Where are props defined?

A

Within the type parameter to ReactDOM.render( ) as:

…propName1=propValue1…

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

What does a React.Component consist of?

A

a single HTMLElement (may have child elements)

17
Q

What’s the first line in a React Component file?

A

import React from ‘react’

18
Q

What’s the difference between default export and multiple exports?

A

export default ExportedClassName

___(figure this out)___

19
Q

What method does every React.Component have?

A

render( )

20
Q

What is fetch( url )?

A

Browser API method that does an AJAX GET request to a given url

21
Q

Why is AJAX done in DidMount instead of WillMount?

A

To ensure that no race condition exists between WillMount and the AJAX request’s callback.

22
Q

How do you render a Component from within another Component’s render method?

A

render (
< ChildComponent /> ;
)

23
Q

How does a child component change the state of something managed by a parent?

A

Set up a method in the parent that runs setState and takes an argument.

Pass a reference to this method to the child via a prop.

Within the child’s render method, use a change handler (i.e. onClick) to invoke the reference, binding to null and passing the argument.

24
Q

Metaphor for understanding props vs state?

A

Props is someone’s notebook that you borrow. It’s weird to make changes to this notebook.

State is your notebook. You can look at someone else’s notebook and safely make changes to your own.