Section 1

Preview this deck

What does the `combineReducers` function do?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (15)

Section 1

(15 cards)

What does the `combineReducers` function do?

Front

This function takes in multiple reducers as parameters and returns an updated state. Each parameter is itself a reducer that manages different parts of state when your app gets too big for a single reducer function.

Back

What is a reducer?

Front

A reducer is a function that accepts state and an action and returns an updated state. They are called upon by actions. Reducers must be pure functions that CAN'T have their state mutated.

Back

What is the purpose of Redux-thunk?

Front

This serves a middleware function for Redux. It overcomes Redux limitations of action creators returning only one action and the inability to run asynchronously.

Back

Why might you not need Redux?

Front

Redux is not needed for smaller applications and when props do NOT need to be passed down multiple generations to children components. Using Redux here might make these applications unnecessarily complicated by introducing a universal Redux state.

Back

How does redux-thunk allow for asynchronous action creators?

Front

Redux-thunk lets you make an action creator that creates a thunk (also an action). The difference now is that API calls are made inside a thunk and are run whenever you want them to run. You can have multiple calls to dispatch in your thunk and utilize them in any order you want.

Back

What does the `mapStateToProps` function do?

Front

This function passes Redux state from store as a prop to a connected React component and is run every time an action is dispatched. Redux state is provided for all connected components and thus have the ability to dispatch actions.

Back

What is Redux? Why would you use it?

Front

Redux is a library to manage state in a separate location from components for large-scaled applications. This prevents prop drilling from a parent component to a child component several generations down and eliminates giving props to intermediate components that have no use for them. State can be broken down into React state for each component or Redux state that can be used by components connected to the Redux store. Redux is also useful when debugging to compare current and previous state.

Back

What is the purpose of the <Provider> component?

Front

Provider is a component from React-Redux and accepts a prop called store which is your Redux state. This is done in index.js by wrapping <Provider> around <App>.

Back

What is a thunk?

Front

A thunk is a function expression that is only run when called. It takes dispatch as an argument and can call dispatch whenever it wants (asynchronously).

Back

What is a store?

Front

Store is a Redux object that holds state for the entire app. Redux state is updated when an action is dispatched on store.

Back

What is an action creator?

Front

An action creator is a function that returns an action (aka an object with a key of "type"). These are usually stored in a separate file called actionTypes.js.

Back

What does the `mapDispatchToProps` function do?

Front

This controls how actions are dispatched from React props to Redux state. It's the second argument of connect() that is/returns an object. Usually actions are imported from another actions.js file and are passed as an object.

Back

What is an action?

Front

An action is an object with a key of "type". They may have additional information usually stored in an object with a key of "payload". Dispatch calls on action, which in turn calls tells reducer to change state.

Back

What is the purpose of the `connect` function? What does it return?

Front

The connect function connects react components with redux state. Actions are dispatched on this.props of a connected component instead of store.

Back

How does data flow in a React/Redux application?

Front

Data flows in 4 steps. The first is to call dispatch (while passing in an action) on the object, store. Next, store calls the reducer function. Reducer updates state and then sends it to store where state is maintained.

Back