Redux & Redux Toolkit Course
Redux & Redux Toolkit
/
Beginner

Global State

Definition

Data that needs to be accessed and updated by many different components across your entire application.

Explain Like I'm New

The 'Public' data. If you log into an app, your Profile Picture needs to show up in the Navbar, on the Settings page, and on the Dashboard. Since so many different pages need it, it is 'Global State'.

Real World Example

A shopping cart in Amazon. You can add items from the homepage, the search results, or the product details page. The cart count in the header updates no matter where you are. That cart is Global State.

Common Use Cases

  • •User authentication status
  • •Shopping carts
  • •Application themes (dark mode)

Terminal Output

bash / terminal
/* Examples of GLOBAL State (Belongs in Redux): - Current logged in User data - List of notifications/alerts - Shopping cart items - Fetched API data that multiple pages need */

Interview Questions

basic

  • Should every single piece of data in your app be put into the Global State?

intermediate

  • What is the primary tool Redux provides for managing Global State?

Flash Cards

Question

Everything in global state?

Click to reveal answer
Answer

NO. Putting everything in the global state makes your app slow and impossible to read. Only data that is TRULY shared across the app should go there.

Question

Primary tool?

Click to reveal answer
Answer

The Redux Store.