Changeset c63036a for my-react-app
- Timestamp:
- 03/03/24 11:00:39 (15 months ago)
- Branches:
- main
- Children:
- 9293100
- Parents:
- cfc16a3
- Location:
- my-react-app/src
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
my-react-app/src/components/Customers.js
rcfc16a3 rc63036a 1 1 import 'bootstrap/dist/css/bootstrap.min.css'; 2 import React, {use Effect, useState} from "react";2 import React, {useContext, useEffect, useState} from "react"; 3 3 import axios from "axios"; 4 4 import { Link } from 'react-router-dom'; 5 5 import { useNavigate } from 'react-router-dom'; 6 import {CustomerContext} from "./CustomerContext"; 6 7 7 8 … … 9 10 const [customers, setCustomers] = useState([]); 10 11 const navigate = useNavigate(); 12 const customersContext = useContext(CustomerContext); 11 13 12 14 useEffect(() => { 13 const fetchCustomers = async () => { 14 try { 15 const response = await axios.get("http://localhost:8080/api/customers"); 16 setCustomers(response.data); 17 } catch (error) { 18 console.error("Error fetching customers: ", error); 19 } 20 }; 21 22 fetchCustomers() 23 }, []); 15 setCustomers(customersContext.customers) 16 }, [customersContext]); 24 17 25 18 const handleDetailClick = (customerId) => { -
my-react-app/src/index.js
rcfc16a3 rc63036a 5 5 import { CuisineProvider } from './components/CuisineContext'; 6 6 import {RestaurantProvider} from "./components/RestaurantContext"; 7 import {CustomerProvider} from "./components/CustomerContext"; 7 8 8 9 const root = ReactDOM.createRoot(document.getElementById('root')); … … 11 12 <CuisineProvider> 12 13 <RestaurantProvider> 13 <App /> 14 <CustomerProvider> 15 <App /> 16 </CustomerProvider> 14 17 </RestaurantProvider> 15 18 </CuisineProvider>
Note:
See TracChangeset
for help on using the changeset viewer.