npm install @y-sweet/react
npm install @y-sweet/sdk
import { getOrCreateDocAndToken } from '@y-sweet/sdk'
export const POST = async (request) => {
// in a production app, you'd want to authenticate the user
// and make sure they have access to the given doc
const body = await request.json()
const docId = body.docId
const clientToken = await
getOrCreateDocAndToken(process.env.CONNECTION_STRING, docId)
return NextResponse.json(clientToken)
}
import { YDocProvider } from '@y-sweet/react'
import { MyApp } from './my-app'
export default function MyComponent() {
const docId = 'my-doc-id'
return (
<YDocProvider
docId={docId}
authEndpoint="/api/auth-doc"
>
<MyApp />
</YDocProvider>
)
}
import { useMap } from '@y-sweet/react'
export function MyApp() {
const items = useMap('colorgrid')
// use Yjs Shared Types to sync document edits
items.set(key, value)
items.delete(key)
}