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.
- useMapreturns a- Y.Mapobject, which maps strings to arbitrary values, similar to a JavaScript object or- Map.
- useArrayreturns a- Y.Arrayobject, which is similar to a JavaScript array.
- useTextreturns a- Y.Textobject, which is similar to a JavaScript string.
💡
In order to use Y-Sweet hooks in a component, it must be a descendant of a YDocProvider.
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.