πQuick Start
Get started now with your React app
In this guide, we will demonstrate how to add collaboration to your React app using the DPAPI custom hooks. These hooks are part of @dpapi/react, a package enabling multiplayer experiences in a matter of minutes.
Configure DPAPI Multiplayer
Install packages
Run the following command to install the DPAPI packages:
npm install --save @dpapi/server @dpapi/reactConnect to DPAPI servers
Create a client that will be responsible to communicate with DPAPI server
import {createClient} from '@dpapi/server'
const client = createClient({
pk_APIkey = "pk_prod_xxxxxxxxxxxxxxxxxxxxxxxx",
});Connect to a DPAPI room
DPAPI uses the concept of rooms, separate virtual spaces where people can collaborate. To create a multiplayer experience, multiple users must be connected to the same room.
RoomProvider is used to create context and make it available to all child components in the React component tree hierarchy. This provides a socket connection to all components that are wrapped in it.
Get other users in the room
Now that the provider is set up, we can start using the DPAPI hooks. First weβll add roomCount, a hook that provides us information about which other users are connected to the room.
Get live cursors in the room
We can add the liveCursors hook to share this information in real-time, and in this case, update the current user cursor position.
Last updated