At the moment I am integrating Websockets into my application and have done so naively in the App component for the time being which ends up a bit like this:
const App = ({ Component, pageProps: { session, ...pageProps } }: AppProps) => {
useEffect(() => {
// setup ws
return () => {
// disonnect
};
}, []);
return (
<SessionProvider session={session}>
<Component {...pageProps} />
</SessionProvider>
);
};
As you can imagine I want to use the user ID from the session object to connect to a private channel based on the user ID. Unfortunately session is undefined when the effect is invoked and useSession() only returns the session further down in the hierarchy. Even having a consumer directly as a child of the SessionProvider yields undefined for useSession(). I am now highly curious where I should obtain the ID in the hierarchy to run the hook.
