Using axios to fetch data from an api and then trying to map the values and display them in a different component.
App.tsx
import React, { useState, useEffect } from 'react';
import JobBoardComponent from './components/JobBoardComponent';
import axios from 'axios';
function App(): JSX.Element {
const[jobs, setJobs] = useState<any>([]);
useEffect((): void => {
const fetchJobs = async () => {
const res = await axios('http://localhost:5000/jobs');
setJobs(res.data);
};
fetchJobs();
}, []);
return (
<div className="App">
{jobs.map((job: any) => <JobBoardComponent job={job} key={job.id} />)}
</div>
);
}
export default App;
JobBoardComponent.tsx
import React from 'react'
function JobBoardComponent( job: any, key: any){
return (
<div>
<h1>{ job }</h1>
</div>
)
}
export default JobBoardComponent;
It looks like the API is working.
I am following this tutorial https://www.youtube.com/watch?v=JZQ8m08cbF0 but I decided to make my own API and now it doesn't work.