General React.js Flashcards

1
Q

React.js is a framework, library or langauage?

A

Library

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

What does a React function look like?

A
function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does a React component look like?

A
class Welcome extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}</h1>;
  }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What notation are React events written?

A

camelCase

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

Where do you bind events?

A

In the constructor

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

How are named modules imported? Default modules?

A

import defaultExport, { namedExport1, namedExport3, etc… } from ‘module’;

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

Difference b/w class component and function?

A

A class component requires you to extend from React.Component and create a render function which returns a React element. Class is required for states.

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

Why use class components?

A

When states are needed

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

How to pass states to a function?

A

If you need a state in your component you will either need to create a class component or you lift the state up to the parent component and pass it down the functional component via props.

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

What is preventDefault() event method?

A
  • ## the default action that belongs to the event will not occur.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does Redux Middleware do?

A

Provides the capability to run code after an action is dispatched, but before the reducer. e.g. 3rd party extension point, logging, aysnc API calls

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

What can middleware be used for?

A

-inspecting the action and state
- modify action
dispatch other actions
- stop actions from reaching reducers

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

What is Thunk?

A

A kind of middleware that subroutine used to inject an additional calculation in another subroutine; allows you to write action creators that return a function instead of an action; use Thunk to generator an API call to a server; used for complex synchronous logic (multiple/conditional dispatches)

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

What is a reducer?

A

Reducers specify how the application’s state changes in response to actions sent to the store.

Reducers calculate a new state given the previous state and an action

Pure function that computes the next state.
Predictable.

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

What are Redux Actions?

A

Payloads of information that send data from your application to your store.
They are the only information for the store. They are sent to the store using store.dispatch().
They are plain JS. They must have a type property that indicates the type of action being performed.

They are ‘what happened’.

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

What is the Redux Store?

A

The object that brings actions and reducers together.

The store:

  • holds application state (tree);
  • allows acces to state via getState();
  • allows state to be updated via dispatch(action);
  • registers listeners
  • handles unregistered listeners

type Store = {
dispatch: Dispatch
getState: () => State
subscribe: (listener: () => void) => () => void
replaceReducer: (reducer: Reducer) => void
}

Only one store made using createStore()

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

What is the dataflow in Redux?

A
  1. You call store.dispatch(action)
  2. The Redux store calls the reducer function you gave it
  3. Root reducer may combine the output of multiple reducers into a single state tree
  4. The Redux store saves the complete state tree returned by the root reducer
18
Q

What is an action creator?

A

A function that creates an action (a payload of information).

19
Q

What is REST?

A

Representational State Transfer using:

  • uses JSON or XML
  • uses web standards (built on HTTP)
  • stateless (server does store states, client does via cookies)
  • uses GET, POST, PUT, DELETE (HTTP)
20
Q

What is a promise?

A

A mechanism that supports async computation; it represents a value that may be available now or in the future;

21
Q

How is a promise written?

A

new Promise (function (resolve, reject) {…});

22
Q

What is fetch?

A

API, promise-based, provides an interface for fetching resources;

23
Q

How is fetch used?

A

fetch(baseUrl + ‘item’)
.then(response => response.json())
.then(data=> console.log(data))
.catch(error => console.log(error.message))

24
Q

What is the format of an arrow function?

A
const myFunction = () => {
  //...
}

const myFunction = (param1, param2) => doSomething(param1, param2)

25
Q

What is the format of an arrow function?

A
const myFunction = () => {
  //...
}

const myFunction = (param1, param2) => doSomething(param1, param2)

26
Q

Does ‘this’ work in an arrow function?

A

No. Due to this, arrow functions are not suited as object methods.

27
Q

Two benefits of arrow functions?

A

A shorter syntax than typical functions

No binding of this

28
Q

What is the syntax of a function expression?

A
const myVariable = function (param) {
statements
}
29
Q

How to change to an arrow function?

A

remove ‘function’ and add => after the params

30
Q

What is a service worker

A

A service worker is a script that your browser runs in the background, separate from a web page, opening the door to features that don’t need a web page or user interaction.

31
Q

Can hooks be called conditionally?

A

No. Must be called in the same order.

32
Q

Can you have a function in useState()?

A

Yes, use for expensive functions to only run once.

33
Q

Can you pass in a function in setState?

A

Yes. Via an arrow function.

34
Q

How do you keep all the values in the current state when setting a new state (setState)?

A

Use …

35
Q

Can you have multiple useState’s in a function?

A

Yes.

36
Q

What is the onChange code to update a form field with a new state using hooks?

A

onChange = {e => setEmail(e.target.value)}

37
Q

What is useEffect?

A

Gets called whenever the component gets re-rendered

Second argument determines when the re-render will happen (when the first function in useEffect is rendered)

Can be used to replace componentDidMount.

38
Q

How can you conditionally render?

A

Hook (useState) && component call

39
Q

What is the return function in useEffect?

A

Cleanup function, unmount.

40
Q

Applications of useEffect?

A

event listners, api’s.