Skip to content

Instantly share code, notes, and snippets.

@nrl240
Last active March 23, 2021 13:18
Show Gist options
  • Save nrl240/4191c2c87131e39d2bbfa9a86a3f3352 to your computer and use it in GitHub Desktop.
Save nrl240/4191c2c87131e39d2bbfa9a86a3f3352 to your computer and use it in GitHub Desktop.
Exit Ticket: Day 16 - Intro to Redux, Action Types and Creators

Exit Ticket: Day 16 - Intro to Redux, Action Types and Creators

You should be able to:

  • Create a Redux store (with a proper reducer and any necessary middleware)
  • Write action types and creators corresponding to your store
  • Subscribe to store changes
  • Dispatch state-changing actions to the store

In your own words, what is Redux and why do we use it?

Redux is used to be a centralized place for our state to live in. Its main use case is when the state of our application gets too large. When this happens, it becomes difficult to maintain in React alone. If we declare our state "too high" and that data is needed in a distant child, the only way React can manage this is to send state as props through many layers of components. This is called "prop drilling." If we declare state "too low," and a distant ancestory needs that data, React is unidirectional and we are not supposed to "pass state back up."

Which is not a core principle of Redux?

  • The store is a single source of truth
  • Only one store can be invoked per app β˜‘οΈ
  • State is read-only
  • Changes are made through actions which flow through your pure reducer

Which of these are methods that are accessible directly from the Redux store? Select all that apply.

Option Explanation Documentation
createStore This is from Redux itself, not the store πŸ”—
reducer We create this ourselves and pass it into the store πŸ”—
β˜‘οΈ getState One of the functions that is given to us by the store πŸ”—
applyMiddleware From Redux itself, not the store πŸ”—
β˜‘οΈ dispatch One of the functions that is given to us by the store πŸ”—
β˜‘οΈ subscribe One of the functions that is given to us by the store πŸ”—
unsubscribe You can say that this is technically given to us by the Redux store, but it is the return value of the subscribe function πŸ”—

Which is not a good use case for Redux?

Use Redux? Option Explanation
β˜‘οΈ A browser-based game with lots of async user events Keeping track of lots of users events that might affect state means it's a pain to keep that all coordinated while making sure each user gets the updates. The single source of truth aspect of Redux helps with this.
β˜‘οΈ An ecommerce store that tracks user authentication across views Tracking auth state across views is a good use case for Redux. The single source of truth aspects prevents us from having to pass auth state to several different components.
β˜‘οΈ A dashboard that updates a series of graphs in real time Same as above. Keeping multiple graphs (components) updated is tedious if we have to pass state around everywhere.
🚫 A fan wiki where users can read hundreds of articles Is there really state being passed around everywhere and shared among multiple views and components? Do we need to keep things in sync? Are there complicated state changing actions? All we need to do here is get the articles and put them in state and display them. There can be a lot contained in state (articles) but state is not complicated.

Which of the following statements are true? Select all the apply.

Option Explanation
Redux is part of the React library Separate library.
React is part of the Redux library Separate library.
Redux is a library for managing components That's React's job.
β˜‘οΈ Redux is a library for managing state
β˜‘οΈ Redux can be used with any JavaScript app It's a separate library so it can be used with anything.
Redux can only be used with React It's definitely used with React a lot, and a lot of blog posts make it seem that way, but, again, it's a separate library that can be used with any JavaScript app if you need a centralized place to manage state.

Extra resources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment