Redux Flashcards

1
Q

What are the parts of the Flux data flow?

A

Action > Dispatcher > Store > View

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

What is Flux?

A

A pattern that uses a unidirectional data flow

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

What are the parts of the Redux data flow?

A

Action > Store > View (only one store, so no need for dispatchers)

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

What are the 3 core principles of Redux?

A
  1. Single source of truth
  2. State is read-only
  3. Changes are made with pure functions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the minimum requirements for sending an action in Redux?

A
  1. It must be an object 2. It must have a type property
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

At a minimum, what argument(s) does redux.createStore method require?

A

The reducer function used by the store; optionally, an initial state object

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

How do you change state when using redux store?

A

Use store.dispatch(); // requires an action

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

How can you add redux store to localStorage every time state is updated?

A
store.subscribe( () => {
  const state = JSON.stringify(store.getState())
  localStorage['react-store'] = state
})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can you get initial state from local storage and set in Redux store?

A

const initialState = localStorage[‘redux-store’] ? JSON.parse(localStorage[‘redux-store’]) : { } // Then pass initialState as second argument to createStore()

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

Where does logic belong in a Redux app?

A

Action Creators, functions that create and return actions

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

How do you associate middleware with your store (how do you get it to run?)

A

Use the applyMiddleware() function from ‘redux’

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

How does myStore.subscribe() work?

A

It listens for any time an action is dispatched to the store; it takes an optional callback function – e.g. to update localStorage.

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

How do you pass the store down the tree of components?

A

Use the redux Provider component.

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

How do you map state from store to properties in a child component?

A

Use the connect() method.

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

How does the redux connect method work?

A

connect(mapStateToProps cb function)(nameOfComponent) // It takes a mapping object and requires a component

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