|
1 | 1 | import { WORKSPACE_EVENT } from '@wabinar/constants/socket-message'; |
2 | 2 | import Mom from 'components/Mom'; |
3 | 3 | import Sidebar from 'components/Sidebar'; |
4 | | -import { useEffect, useState } from 'react'; |
| 4 | +import { useEffect, useMemo, useState } from 'react'; |
5 | 5 | import { useParams } from 'react-router-dom'; |
6 | 6 | import { getWorkspaceInfo } from 'src/apis/workspace'; |
7 | 7 | import MeetingMediaBar from 'src/components/MeetingMediaBar'; |
@@ -56,11 +56,20 @@ function Workspace() { |
56 | 56 | }; |
57 | 57 | }, [workspaceSocket]); |
58 | 58 |
|
59 | | - if (!momSocket || !workspaceSocket) return <></>; |
| 59 | + const memoizedSocketValue = useMemo( |
| 60 | + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
| 61 | + () => ({ momSocket: momSocket!, workspaceSocket: workspaceSocket! }), |
| 62 | + [momSocket, workspaceSocket], |
| 63 | + ); |
| 64 | + |
| 65 | + const memoizedOnGoingValue = useMemo( |
| 66 | + () => ({ isOnGoing, setIsOnGoing }), |
| 67 | + [isOnGoing], |
| 68 | + ); |
60 | 69 |
|
61 | 70 | return ( |
62 | | - <SocketContext.Provider value={{ momSocket, workspaceSocket }}> |
63 | | - <MeetingContext.Provider value={{ isOnGoing, setIsOnGoing }}> |
| 71 | + <SocketContext.Provider value={memoizedSocketValue}> |
| 72 | + <MeetingContext.Provider value={memoizedOnGoingValue}> |
64 | 73 | {workspace && ( |
65 | 74 | <SelectedMomContext.Provider value={{ selectedMom, setSelectedMom }}> |
66 | 75 | <Sidebar workspace={workspace} /> |
|
0 commit comments