| 14 | useEffect(() => { |
| 15 | // Fetch the data from the API when the component mounts |
| 16 | const fetchProjects = async () => { |
| 17 | try { |
| 18 | const response = await axios.get(`${VITE_SERVER_PORT}/api/showcaseProjects/all-projects`); |
| 19 | setProjects(response.data); // Store the fetched projects in state |
| 20 | setLoading(false); // Set loading to false after data is fetched |
| 21 | } catch (err) { |
| 22 | setError('Error fetching projects'); |
| 23 | setLoading(false); // Set loading to false if an error occurs |
| 24 | } |
| 25 | }; |
| 26 | |
| 27 | fetchProjects(); // Call the function to fetch data |
| 28 | }, []); // Empty dependency array means this effect runs once on mount |