Udemy - Redux Flashcards
What is Redux?
A library that makes it possible to manage more complex state.
What is the Redux store?
An object.
Give an example of a Redux store:
{ expenses: [{ _id: 'abc', description: 'rent', amount: 109500 }] }
What are the shortcomings of using component state?
In complex apps, there may be no clear parent component where we can store the state.
Components aren’t reusable if they need things from the parent.
What two things can each component define in Redux?
What data it needs.
What data it needs to be able to change.
How do you install Redux?
yarn add redux@x
What’s the first thing you do in Redux?
Import the createStore function.
How would you import the store function from Redux?
import { createStore } from ‘redux’;
How many times would you call createStore?
Once.
How would you create a store?
const store = createStore((state = { count: 0 }) => { return state; });
Can you call createStore without any arguments?
No.
What is the first argument createStore expects?
A function (state).
What does state mean in this code?
const store = createStore((state) => { return state; });
The current state.
What does state = { count: 0 } mean in this code?
const store = createStore((state = { count: 0 }) => { return state; });
Because we don’t have a constructor function where we set up the default we set it up here.
What does the store.getState() method do?
Returns the current state object.
How could you view the state object in this code in the console?
const store = createStore((state = { count: 0 }) => { return state; });
console.log(store.getState());
What do actions allow us to do?
Change the Redux store.
What is an action?
An object that gets sent to the store. This object describes the type of action we’d like to take.
How do you create an action?
Define an object, with a type property.
What is the single property you have to define on an action?
The type property.
What Redux convention does the action objects type property value use?
Written in all upper case with an underscore to separate multiple words.
What do you do after you define a type property on an action object?
Send it to the store.
How would you send an action to the store.
By calling a method on store called store.dispatch();
What does dispatch allow us to do?
Send off an action object.