tldraw/hooks/useLoadOnMount.ts

22 lines
583 B
TypeScript
Raw Normal View History

2021-06-21 21:35:28 +00:00
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2021-06-17 10:43:55 +00:00
import { useEffect } from 'react'
import state from 'state'
2021-06-30 20:33:30 +00:00
export default function useLoadOnMount(roomId?: string) {
useEffect(() => {
2021-06-17 10:43:55 +00:00
const fonts = (document as any).fonts
2021-06-28 20:45:06 +00:00
fonts.load('12px Verveine Regular', 'Fonts are loaded!').then(() => {
state.send('MOUNTED')
2021-06-30 20:33:30 +00:00
if (roomId !== undefined) {
state.send('RT_LOADED_ROOM', { id: roomId })
}
2021-06-28 20:45:06 +00:00
})
2021-06-17 10:43:55 +00:00
2021-05-17 21:27:18 +00:00
return () => {
2021-06-17 10:43:55 +00:00
state.send('UNMOUNTED')
2021-06-28 20:45:06 +00:00
state.send('RT_UNLOADED_ROOM', { id: roomId })
2021-05-17 21:27:18 +00:00
}
2021-06-28 20:45:06 +00:00
}, [roomId])
}