main
Last change
on this file was 8ca35dc, checked in by Aleksandar Panovski <apano77@…>, 4 months ago |
Done with stupid timeslots
|
-
Property mode
set to
100644
|
File size:
784 bytes
|
Rev | Line | |
---|
[cfc16a3] | 1 | import React, { createContext, useState, useEffect } from 'react';
|
---|
| 2 | import axios from 'axios';
|
---|
| 3 |
|
---|
| 4 | export const CuisineContext = createContext();
|
---|
| 5 |
|
---|
| 6 | export const CuisineProvider = ({ children }) => {
|
---|
| 7 | const [cuisineTypes, setCuisineTypes] = useState([]);
|
---|
| 8 |
|
---|
| 9 | useEffect(() => {
|
---|
| 10 | const fetchCuisineTypes = async () => {
|
---|
| 11 | try {
|
---|
[8ca35dc] | 12 | const response = await axios.get('http://localhost:8081/api/cuisineTypes');
|
---|
[cfc16a3] | 13 | setCuisineTypes(response.data);
|
---|
| 14 | } catch (error) {
|
---|
| 15 | console.error('Error fetching cuisine types:', error);
|
---|
| 16 | }
|
---|
| 17 | };
|
---|
| 18 | fetchCuisineTypes();
|
---|
| 19 | }, []);
|
---|
| 20 |
|
---|
| 21 | return (
|
---|
| 22 | <CuisineContext.Provider value={cuisineTypes}>
|
---|
| 23 | {children}
|
---|
| 24 | </CuisineContext.Provider>
|
---|
| 25 | );
|
---|
| 26 | }; |
---|
Note:
See
TracBrowser
for help on using the repository browser.