createPresenceStateDerivation
See source codeCreates a derivation that represents the current presence state of the current user.
This function returns a derivation factory that, when given a store, creates a computed signal containing the user's current presence state. The presence state includes information like cursor position, selected shapes, camera position, and user metadata that gets synchronized in multiplayer scenarios.
function createPresenceStateDerivation(
$user: Signal<TLPresenceUserInfo>,
instanceId?: TLInstancePresence['id']
): (store: TLStore) => Signal<null | TLInstancePresence>
Example
import { atom } from '@tldraw/state'
import { createPresenceStateDerivation } from '@tldraw/tlschema'
const userSignal = atom('user', {
id: 'user-123',
name: 'Alice',
color: '#ff0000',
})
const presenceDerivation = createPresenceStateDerivation(userSignal)
// Use with a store to get reactive presence state
const presenceState = presenceDerivation(store)
console.log(presenceState.get()) // Current user presence or null
Parameters
Name | Description |
---|---|
| A reactive signal containing the user information |
|
Optional custom instance ID. If not provided, one will be generated based on the store ID |
Returns
(store: TLStore) => Signal<null | TLInstancePresence>
A function that takes a store and returns a computed signal of the user's presence state
Prev
createBindingValidatorNext
createShapeId