Advanced
Y-Sweet Hooks

Y-Sweet Hooks

The y-sweet hooks allow you to to sync and update data for a document. These hooks provide objects similar to built-in JavaScript types, but which are automatically synchronized across the network and persisted.

  • useMap returns a Y.Map object, which maps strings to arbitrary values, similar to a JavaScript object or Map.
  • useArray returns a Y.Array object, which is similar to a JavaScript array.
  • useText returns a Y.Text object, which is similar to a JavaScript string.

In the color grid example (opens in a new tab), we use a map to store the color of each cell in a grid. Similar to a JavaScript Map (but different than a JS object), we use .get() and .set() to read and write values.

Refer to the api reference (opens in a new tab) for more details on how to use the hoooks.

y-sweet was created by Drifting in Space.