Build your own Redux Flashcards

1
Q

What are race conditions?

A

Race conditions occur when two computer program processes, or threads, attempt to access the same resource at the same time and cause problems in the system.

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

What is the main benefit of Redux in comparison to not using it?

A

It constrains how and where you can change the state of your app.

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

What is a reducer and what does it do?

A

A reducer is a function that takes the current state and an action object and returns the new state.

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

What is the dictionary definition of Immutable?

A

unchanging over time or unable to be changed.

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

What are the two types of equality most worth mentioning in JS?

A

reference equality
value equality

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

What does this demonstrate ?

var yourCar = {
color: ‘red’,
.. the same as neighboursCar
};

var neighboursCar = {
color: ‘red’,
… the same as yourCar
};

valueEqual(yourCar, neighboursCar); // true;
yourCar === neighboursCar; // false

yourCar.color = ‘blue’;

valueEqual(yourCar, neighboursCar); // false;
yourCar === neighboursCar; // false

A

Mutations do not change the results of reference equality checks. They change the results of value equality checks.

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

What sentence can help you apply data immutability?

A

Whenever your object would be mutated, don’t do it. Instead, create a changed copy of it.

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

What is one important mutation that is allowed with Redux?

A

A variable inside the redux store is allowed to be mutated.

There is a single variable that points to the state object, and we keep changing that variable to point to the next state. That is one important mutation that is allowed in your app, but we’ll control that mutation inside a store.

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

What question can you ask yourself to decide whether to use local state or redux state?

A

Does this state need to exist after this component is unmounted?

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

What are the three steps to using React’s Context feature?

A
  1. Create a context object outside of any component.
    const ReduxContext = createContext(null);
  2. Wrap your component in the context provider.
    const Provider = ({ store, children }) => {
    return (
    <ReduxContext.Provider value={store}>{children}</ReduxContext.Provider>
    );
    };
  3. Access the value the context provides using useContext in any components that are children of the Provider.
    const TestApp = () => {
    const store = useContext(ReduxContext);
    console.log(“The redux store”, store.getState());
    return <h1>This app is sick!</h1>;
    };
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a higher order component in React?

A

a higher-order component is a function that takes a component and returns a new component.

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

Why is a Redux reducer called a reducer?

A

It is called a reducer because it works like a reducer callback. A reducer callback that is building a final object will return a new object on every iteration, at the end of the reduce we have a final object. This is what a Redux reducer does it returns a new object(state). After multiple dispatches you will have run multiple reducers resulting in the current state.

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