Build your own Redux Flashcards
What are race conditions?
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.
What is the main benefit of Redux in comparison to not using it?
It constrains how and where you can change the state of your app.
What is a reducer and what does it do?
A reducer is a function that takes the current state and an action object and returns the new state.
What is the dictionary definition of Immutable?
unchanging over time or unable to be changed.
What are the two types of equality most worth mentioning in JS?
reference equality
value equality
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
Mutations do not change the results of reference equality checks. They change the results of value equality checks.
What sentence can help you apply data immutability?
Whenever your object would be mutated, don’t do it. Instead, create a changed copy of it.
What is one important mutation that is allowed with Redux?
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.
What question can you ask yourself to decide whether to use local state or redux state?
Does this state need to exist after this component is unmounted?
What are the three steps to using React’s Context feature?
- Create a context object outside of any component.
const ReduxContext = createContext(null); - Wrap your component in the context provider.
const Provider = ({ store, children }) => {
return (
<ReduxContext.Provider value={store}>{children}</ReduxContext.Provider>
);
}; - 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>;
};
What is a higher order component in React?
a higher-order component is a function that takes a component and returns a new component.
Why is a Redux reducer called a reducer?
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.