Y-Sweet React Hooks
The Y-Sweet React hooks allow you to sync and update data for a document from a React component. Many of these hooks return Y.js shared types, which are similar to built-in JavaScript types, but which are automatically synchronized across the network and persisted.
useMap
returns aY.Map
object, which maps strings to arbitrary values, similar to a JavaScript object orMap
.useArray
returns aY.Array
object, which is similar to a JavaScript array.useText
returns aY.Text
object, 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>
component.
In the color grid example, 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 for more details on how to use the hoooks.