Syntax - Tasty Web Development Treats

850: Manage State in JavaScript Like a Pro!

· Summarized

Share this episode
Anyone with this link can open it.
Share Link
Start at 0:00

Key takeaways

  • State management is essential for maintaining the current condition of applications, with various libraries and approaches available.
  • Understanding the terminology of state management such as reactive state, stores, and immutability can significantly enhance application architecture.
  • Choosing the right state management approach depends on specific use cases—reducer-based, mutation-based, or atom-based state management all have unique advantages.
  • Utilizing the URL for state management is an underappreciated method that aids in creating sharable and filterable web applications.
  • Different libraries serve specific needs in state management, and understanding their features can lead developers to implement the most efficient solutions.

Summary

Introduction to State Management

In this episode, Wes Bos and Scott Tolinski delve into the significant topic of state management in JavaScript. They emphasize the universal necessity of state management across various applications, showcasing different libraries and approaches. Key concepts such as global and local state, reactive state, and other terminologies related to state management are introduced.

Understanding State and Its Terminology

The hosts break down crucial terminology relevant to state management, including reactive state, stores, mutability, and state updaters. They explain how reactive state allows templates to update with data changes and discuss the implications of immutable versus mutable state along with functional components such as signals and observables.

Approaches to State Management

Wes and Scott discuss several key approaches to managing state, including reducer-based state (e.g., Redux), mutation-based state, and atom-based state. They explore the advantages and disadvantages of each method and provide examples of scenarios where each is best applicable, emphasizing the use of libraries like Zustand and Jotai for different use cases.

Handling State in Applications

The podcast discusses various ways to hold state, touching on practical implementations like state stored in objects, URLs, IndexedDB, and the Browser's native storage. The significance of the URL as an age-old state management tool is highlighted, demonstrating how filters and sorting can be managed within web applications.

Global vs Local State

The conversation transitions to differentiating global state, which can be accessed application-wide, from local state, which is confined to specific components. The hosts provide practical examples to illustrate when to use global versus local state, offering insights on effective state sharing strategies.

Exploring State Libraries and Tools

The episode reviews multiple state management libraries available in the JavaScript ecosystem, including Zustand, Jotai, xState, Easy Peasy, and Pinia. Each tool's features and applications are dissected, and the hosts discuss their personal experiences choosing tools appropriate for complex applications.

Conclusion and Sick Picks

In closing, Wes and Scott share their personal recommendations ('sick picks'), which include men's body wash and bento boxes as practical gifts. They wrap up the episode with a reminder for listeners to subscribe to their YouTube channel for more insights.

Sponsors

  • Sentry.io · Sentry promotes the open-source pledge encouraging companies to pledge part of their profits back to open-source development.

Show notes

Scott and Wes serve up state management in JavaScript, breaking down key concepts like reactive state, state updaters, and global vs local state. They also explore various approaches and libraries, mutation-based state, and tools like Zustand and xState, to help you manage state like a pro.
Show Notes 00:00 Welcome to Syntax!
01:22 Brought to you by Sentry.io.
03:10 What is state?
03:29 Common state jargon. 03:48 Reactive State.
04:14 Store.
04:46 Immutable vs Mutable State.
05:53 State updaters.
06:15 Signals. Solid.js Signal Docs.

06:49 Observables.
07:07 UI is a function of state.
08:39 State Machine.
10:58 Binding state.
11:36 Global vs local.
11:49 Computed State, derived state, selector state.

12:41 Approaches to state management. 12:52 Reducer based.
16:39 Mutation based state.
21:17 Atom based state.

25:15 Ways to hold state. 25:17 Holding state in an object.
27:38 Holding state in the URL. Syntax Shows.

29:34 Holding state in IndexedDB, local storage, and cookies.
32:16 Holding state with FormData.
33:56 Holding state with Signals. Signals Proposal.

37:27 Holding state with the server database.

38:55 Global State vs Component State. Habit Path.

40:39 Sharing state. 42:58 State libraries.
45:26 Zustand.
50:24 Jotai.
51:50 xState.
54:56 Easy Peasy.
55:24 Pinia.
56:01 TanStack Query.

57:02 Sick Picks + Shameless Plugs.
Sick Picks Scott: Cremo Mens Body Wash, Bentgo Adult.
Wes: Adult Bento Box.
Shameless Plugs Wes: Syntax on YouTube.
Hit us up on Socials! Syntax: X Instagram Tiktok LinkedIn Threads
Wes: X Instagram Tiktok LinkedIn Threads
Scott: X Instagram Tiktok LinkedIn Threads
Randy: X Instagram YouTube Threads

Follow this show on AudioBrevity and new episodes get summarized for you. Create a free account

Couldn't load the audio. A blocker may be stopping the show's tracking links. Open the file