generated from HackYourFuture-CPH/hyf-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.jsx
49 lines (43 loc) · 1.37 KB
/
main.jsx
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
43
44
45
46
47
48
49
import React from "react";
import ReactDOM from "react-dom/client";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import HomePage from "./components/HomePage/HomePage.jsx";
import TestPage from "./components/TestPage/TestPage.jsx";
import "./main.css";
import MealsList from "../frontend/components/MealsList.jsx";
import MealDetailPage from "../frontend/components/MealDetailPage.jsx";
const router = createBrowserRouter([
{
path: "/",
element: <HomePage />,
},
// This route can be removed and replaced with your own page
{
path: "/nested",
element: <TestPage />,
},
{
path: "/meal",
element: <MealsPage />,
},
{
path: "/meals/:id",
element: <MealDetailPage />,
},
], { future: { v7_startTransition: true } });
// Create a new MealsPage component to fetch and pass meals to MealsList
function MealsPage() {
const [meals, setMeals] = useState([]);
useEffect(() => {
fetch("http://localhost:3001/api/all-meals")
.then((response) => response.json())
.then((data) => setMeals(data))
.catch((error) => console.error("Error fetching meals:", error));
}, []);
return <MealsList meals={meals} />;
}
ReactDOM.createRoot(document.getElementById("root")).render(
<React.StrictMode>
<RouterProvider router={router} />
</React.StrictMode>,
);