You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

useLoadOnMount.ts 840B

123456789101112131415161718192021222324252627
  1. /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
  2. import { useEffect } from 'react'
  3. import state from 'state'
  4. // import coopState from 'state/coop/coop-state'
  5. export default function useLoadOnMount(roomId?: string) {
  6. useEffect(() => {
  7. if ('fonts' in document) {
  8. const fonts = (document as any).fonts
  9. fonts.load('12px Verveine Regular', 'Fonts are loaded!').then(() => {
  10. state.send('MOUNTED', { roomId })
  11. // if (roomId !== undefined) {
  12. // state.send('RT_LOADED_ROOM', { id: roomId })
  13. // coopState.send('JOINED_ROOM', { id: roomId })
  14. // }
  15. })
  16. } else {
  17. setTimeout(() => state.send('MOUNTED'), 1000)
  18. }
  19. return () => {
  20. state.send('UNMOUNTED', { roomId })
  21. // coopState.send('LEFT_ROOM', { id: roomId })
  22. }
  23. }, [roomId])
  24. }