Redux Flashcards

1
Q

Redux can be described in three fundamental principles:

A
  • single source of truth
  • state is read only
  • changes are made with pure functions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Single source of truth

A

The global state of your application is stored in an object tree within a single store.

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

State is read-only

A

The only way to change the state is to emit an action, an object describing what happened.

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

Changes are made with pure functions

A

Reducers are just pure functions that take the previous state and an action, and return the next state

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

What is Redux

A

Redux is a pattern and library for managing and updating application state, using events called “actions”.

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

Why I need Redux

A

Redux helps you manage “global” state - state that is needed across many parts of your application.

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

Como instalar redux en un proyecto

A

yarn add redux react-redux

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

Después de importar redux, creamos un ___ valido porque se necesita obligatorio en el store, aunque este vacío

A

reducer

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

Luego en el index.js se importa ____ de redux y ___ de react-redux

A

createStore y Provide

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

Que se le debe pasar a createStore?

A

const store = createStore( reducers,

// all reducers go here

{}

//initial state );

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

Ahora metemos nuestro en el ____ y le mandamos el store

A

Provider

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

What is Flux?

A

architecture that complements React and the concept of Unidirectional Data Flow.

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

Los datos viajan unidirreccional, teniendo un unico camino, y un sitio donde se almacena el estado

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

What is Redux DevTools?

A

Redux DevTools is a live-editing time travel environment for redux with hot reloading, action replay, and customizable UI.

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

How to add multiple middlewares to Redux?

A

You can use applyMiddleware where you can pass each piece of middleware as a new argument. So you just need to pass each piece of middleware you’d like. For example, you can add Redux Thunk and logger middlewares as an argument as below,

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

How to set initial state in Redux?

A

You need to pass initial state as second argument to createStore

17
Q

How to structure Redux top level directories?

A
  1. Components Used for “dumb” React components unaware of Redux 2. Containers Used for “smart” React components connected to Redux 3. Actions Used for all action creators, where file name corresponds to part of the app 4. Reducers Used for all reducers, where file name corresponds to state key 5. Store Used for store initialization This structure works well for small and mid-level size apps.
18
Q

What are Redux selectors and Why to use them?

A

Selectors are functions that take Redux state as an argument and return some data to pass to the component. For example, to get user details from the state:

19
Q

What are reducers in redux?

A

The reducer is a pure function that takes the previous state and an action, and returns the next state.

20
Q

Things you should never do inside a reducer:

A
  • Mutate its arguments;
  • Perform side effects like API calls and routing transitions;
  • Call non-pure functions, e.g. Date.now() or Math.random().
21
Q

What are the features of Redux DevTools?

A
  1. Lets you inspect every state and action payload
  2. Lets you go back in time by “cancelling” actions
22
Q

What is Redux Thunk?

A

Redux Thunk middleware allows you to write action creators that return a function instead of an action.

23
Q

The ___can be used to delay the dispatch of an action, or to dispatch only if a certain condition is met.

A

thunk

24
Q

What is redux-saga?

A

redux-saga is a library that aims to make side effects (i.e. asynchronous things like data fetching and impure things like accessing the browser cache)

25
Q

What is the difference between React context and React redux?

A

You can use Context in your application directly and is going to be great for passing down data to deeply nested components which what it was designed for. Whereas Redux is much more powerful and provides a large number of features that the Context Api doesn’t provide.

26
Q

How to use connect from react redux?

A

You need to follow two steps to use your store in your container 1. Use mapStateToProps(): It maps the state variables from your store to the props that you specify 2. Connect the above props to your container: The object returned by the mapStateToProps component is connected to the container. You can import connect from react-redux like

27
Q

What are the differences between redux-saga and redux-thunk?

A

Both Redux Thunk and Redux Saga take care of dealing with side effects. In most of the scenarios, Thunk allows Promises to deal with them, whereas Saga uses Generators.

28
Q

What is the purpose of the constants in Redux?

A

Constants allow you to easily find all usages of that specific functionality across the project when you use an IDE. It also prevents you from introducing silly bugs caused by typos – in which case, you will get a ReferenceError immediately.

29
Q

What is the proper way to access Redux store?

A

The best way to access your store through a component is using the connect() function. Actually creates a new component that wraps around your existing one! This pattern is called Higher-Order Components, and is generally the preferred way of extending a component’s functionality in React. This allows you to map state and action creators to your component, and have them passed in automatically as your store updates. Let’s take an example of FilterLink component using connect.

30
Q

Why are Redux state functions called as reducers?

A

Reducers always return the accumulation of the state (based on all previous and current actions) not only default values. Therefore, they act as a reducer of state. Each time a redux reducer is called, the state is passed in with the action (state, action). This state is then reduced (or accumulated) based on the action, and then the next state is returned. i.e, You could “reduce” a collection of actions and an initial state (of the store) on which to perform these actions to get the resulting final state.