Use fetch and useEffect in App to load todos from the JSONPlaceholder API.
API endpoint
https://jsonplaceholder.typicode.com/todos
Acceptance criteria
- In
App.tsx, import useEffect and mapTodoToTicket.
- Initialize tickets as an empty array:
const [tickets, setTickets] = useState<Ticket[]>([]);
- Add a
useEffect with [] as dependency array that:
- Sets
isLoading to true.
- Calls
fetch('https://jsonplaceholder.typicode.com/todos').
- Converts the response to JSON.
- Takes only the first ~15 todos:
todos.slice(0, 15).
- Maps them with
mapTodoToTicket.
- Calls
setTickets(mappedTickets).
- In case of error, sets
error to a friendly message like 'Failed to load tickets'.
- In
finally (or after both success/error paths), sets isLoading back to false.
- Confirm in the UI that the board now uses API data instead of
mockData.
Use
fetchanduseEffectinAppto load todos from the JSONPlaceholder API.API endpoint
https://jsonplaceholder.typicode.com/todosAcceptance criteria
App.tsx, importuseEffectandmapTodoToTicket.const [tickets, setTickets] = useState<Ticket[]>([]);useEffectwith[]as dependency array that:isLoadingtotrue.fetch('https://jsonplaceholder.typicode.com/todos').todos.slice(0, 15).mapTodoToTicket.setTickets(mappedTickets).errorto a friendly message like'Failed to load tickets'.finally(or after both success/error paths), setsisLoadingback tofalse.mockData.