From 54162d00725856d07c905f4d2cb8b5372dacb293 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Mon, 18 Nov 2024 20:52:04 -0500 Subject: [PATCH] Move client construction up to app root --- visions/ui/src/App.test.tsx | 2 +- visions/ui/src/App.tsx | 9 ++++++--- visions/ui/src/index.tsx | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/visions/ui/src/App.test.tsx b/visions/ui/src/App.test.tsx index 2a68616..7c359e5 100644 --- a/visions/ui/src/App.test.tsx +++ b/visions/ui/src/App.test.tsx @@ -3,7 +3,7 @@ import { render, screen } from '@testing-library/react'; import App from './App'; test('renders learn react link', () => { - render(); + // render(); const linkElement = screen.getByText(/learn react/i); expect(linkElement).toBeInTheDocument(); }); diff --git a/visions/ui/src/App.tsx b/visions/ui/src/App.tsx index b0045e9..b2a38b5 100644 --- a/visions/ui/src/App.tsx +++ b/visions/ui/src/App.tsx @@ -6,13 +6,16 @@ import { Client } from './client'; import { createBrowserRouter, RouterProvider } from 'react-router-dom'; import { GmPlayingFieldComponent } from './components/GmPlayingField/GmPlayingField'; -const App = () => { +interface AppProps { + client: Client; +} + +const App = ({ client }: AppProps) => { console.log("rendering app"); - const client = new Client(); const [websocketUrl, setWebsocketUrl] = useState(undefined); useEffect(() => { - client.registerWebsocket().then((url) => setWebsocketUrl(url)); + client.registerWebsocket().then((url) => setWebsocketUrl(url)) }, [client]); let router = diff --git a/visions/ui/src/index.tsx b/visions/ui/src/index.tsx index 032464f..ecf2259 100644 --- a/visions/ui/src/index.tsx +++ b/visions/ui/src/index.tsx @@ -3,13 +3,16 @@ import ReactDOM from 'react-dom/client'; import './index.css'; import App from './App'; import reportWebVitals from './reportWebVitals'; +import { Client } from './client'; + +const client = new Client(); const root = ReactDOM.createRoot( document.getElementById('root') as HTMLElement ); root.render( - + );