Skip to content
English

Zustand

The Zustand panel has three tabs. State shows each store’s current state and lets you edit its values. Changes lists every change with a diff, and can unwind a store to any of them. Call runs a store’s actions with arguments you enter.

Setting up Zustand in the SDK

The Zustand panel's State tab with a store selected and a nested object expanded

Stores are listed on the left, and the first is selected. The State tab shows the selected store’s state as a tree. Use Expand all and Collapse all to open or close every branch, and Copy to copy the whole state as JSON.

Values that aren’t JSON are shown as text: a function as ƒ name(), a Date as an ISO string, and undefined as undefined. A Map shows as an object and a Set as an array.

Type in Filter state… to find keys and values that contain the text, ignoring case. Matches are highlighted and their branches open.

Type a full path, such as evidence.forensics.fingerprints, to show only that value. Array items are numbered, as in suspects.0. As you type a path, the keys at that level are suggested. Press the Enter or Tab key to accept one, or . to accept it and go a level deeper. To delete the last part of the path, press Option+Backspace, or Ctrl+Backspace on Windows and Linux.

Double-click a string, number, boolean or null to edit it, or tab to it and press Enter. Press Enter to save, or Escape or click away to cancel. A string takes any text. Other values take a JSON value, so to change a number into a string, type it in quotes.

Hover an array to change its items:

  • Add item on the array adds an item at the start.
  • Add item after… on an item adds one after it.
  • Remove item removes the item.

When you add an item, choose String, Number, Boolean or Null, then edit its value. Keys can’t be added to or removed from objects, and functions and other non-JSON values can’t be edited.

Each edit is made in your app and appears in Changes as @@xerlock/edit.

The Changes tab with a named change selected and its diff open in the details pane

The Changes tab lists changes from every store, with the newest at the bottom. Each shows its time, its store, and its name in bold, or the keys it changed. The list follows new changes while you’re scrolled to the bottom.

Type in Filter changes… to show changes whose store, name or keys contain the text, ignoring case, and use Filter by store to show one store. Clear changes empties the list.

Select a change to open it:

  • Diff lists each value that was Added, Removed or Changed, with its before and after values.
  • Before and After show the store’s whole state either side of the change.

The list is kept when your app reloads. Before and after states are kept for the last historyLimit changes of each store, and only until your app reloads or reconnects. For other changes, the pane shows “State for this change is no longer available.”

Unwind to here, on a change or in its details pane, returns that store to its state right after the change. Its later changes are removed from the list, and the unwind isn’t added as a change. Other stores aren’t affected, and the actions in the state keep working. It only works for changes whose before and after states are still available.

The Call tab with an action selected, its arguments prefilled, and a recent call listed

On the Call tab, pick a store, then choose one of its actions in Select an action…. Actions with a template from callable() or callableAction() are marked template, and choosing one fills in its template. Otherwise the editor is filled with the arguments of the action’s last call.

Enter the arguments as a JSON array, such as ["Irene Adler"]. An empty editor calls the action with no arguments. Then click Call.

Async actions are awaited. You’ll see “Called …” when the action finishes, or “The action threw: …” with its error message. What the action returns isn’t shown.

Recent calls lists the last 10 successful calls. Call again repeats one, and Edit loads it into the editor.

  • Only top-level functions are listed as actions. Functions inside nested objects aren’t.