npm.io
1.1.4 • Published 3 years ago

use-y-js

Licence
MIT
Version
1.1.4
Deps
7
Size
17 kB
Vulns
0
Weekly
0
Stars
2

useYjs

A custom hook simplifies to create of a CRDT document.

Manual

1.Start a signaling y-websocket server

PORT=4444 npx y-websocket

Read more: y-websocket

2.Intall use-y-js

npm install use-y-js

3.Import hook and start coding

import { useYjs } from "use-y-js";
// ...
const { data, updateData, userInfoMap, updateFieldLocalUserInfo } = useYjs({
  signaling: "ws://localhost:4444",
  roomName: "your-room-name",
  // use for auth
  params: {
    token: "anthing"
  }
  // POJO
  initData: {
    title: "Doc title",
    content: "Doc content"
  },
  // POJO
  initUserInfo: {
    name: "Rio",
    color: "#166f9c",
    pointerLocation:  {
      x: 100,
      y: 200
    }
  },
  // Minimum time until the next userInfo data sync, defaultValue = 250
  intervalSyncTime: 300
});

Demo

Example

Keywords