From a0f288e1ac1e1ca53e5bc2dd7e91fbdce9ed9b4f Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Wed, 1 Nov 2023 04:45:13 -0700 Subject: [PATCH] Create silver-nails-explain.md --- .changeset/silver-nails-explain.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .changeset/silver-nails-explain.md diff --git a/.changeset/silver-nails-explain.md b/.changeset/silver-nails-explain.md new file mode 100644 index 0000000000..593e518a95 --- /dev/null +++ b/.changeset/silver-nails-explain.md @@ -0,0 +1,23 @@ +--- +"@latticexyz/store-sync": minor +--- + +Added a Zustand storage adapter and corresponding `syncToZustand` method for use in vanilla and React apps. It's used much like the other sync methods, except it returns a bound store and set of typed tables. + +```ts +import { syncToZustand } from "@latticexyz/store-sync/zustand"; +import config from "contracts/mud.config"; + +const { tables, useStore, latestBlock$, storedBlockLogs$, waitForTransaction } = await syncToZustand({ + config, + ... +}); + +// in vanilla apps +const positions = useStore.getState().getRecords(tables.Position); + +// in React apps +const positions = useStore((state) => state.getRecords(tables.Position)); +``` + +This change will be shortly followed by an update to our templates that uses Zustand as the default client data store and sync method.