-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.tsx
42 lines (35 loc) · 988 Bytes
/
main.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { StrictMode } from "react";
import ReactDOM from "react-dom/client";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import { ApiProvider, ElectionListProvider } from "@kiesraad/api";
// ignore in prod
import { startMockAPI } from "./msw-mock-api.ts";
import { routes } from "./routes.tsx";
const rootDiv = document.getElementById("root");
if (!rootDiv) throw new Error("Root div not found");
const root = ReactDOM.createRoot(rootDiv);
function render() {
const router = createBrowserRouter(routes, {
future: {
v7_normalizeFormMethod: true,
},
});
root.render(
<StrictMode>
<ApiProvider host={process.env.API_HOST || ""}>
<ElectionListProvider>
<RouterProvider router={router} />
</ElectionListProvider>
</ApiProvider>
</StrictMode>,
);
}
if (process.env.MSW) {
startMockAPI()
.then(render)
.catch((e: unknown) => {
console.error(e);
});
} else {
render();
}