File tree Expand file tree Collapse file tree 3 files changed +17
-12
lines changed
Section9-React-with-TypeScript/reminders-app/src Expand file tree Collapse file tree 3 files changed +17
-12
lines changed Original file line number Diff line number Diff line change 1- import React , { useState } from "react" ;
1+ import React , { useEffect , useState } from "react" ;
22import logo from "./logo.svg" ;
33import "./App.css" ;
44import ReminderList from "./components/ReminderList" ;
55import Reminder from "./models/reminder" ;
6-
6+ import reminderService from "./services/reminder" ;
77
88function App ( ) {
9- const [ reminders , setReminders ] = useState < Reminder [ ] > ( [
10- { id : 1 , title : "Reminder 1" } ,
11- ] ) ;
9+ const [ reminders , setReminders ] = useState < Reminder [ ] > ( [ ] ) ;
10+
11+ useEffect ( ( ) => {
12+ loadReminders ( ) ;
13+ } , [ ] ) ;
14+
15+ const loadReminders = async ( ) => {
16+ const reminders = await reminderService . getReminder ( ) ;
17+ setReminders ( reminders ) ;
18+ } ;
1219
1320 return (
1421 < div className = "App" >
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import Reminder from '../models/reminder' ;
33
4-
5-
64interface ReminderListProps {
75 items : Reminder [ ]
86}
97
108function ReminderList ( { items } : ReminderListProps ) {
119 return (
12- < ul >
13- { items . map ( items => < li key = { items . id } > { items . title } </ li > ) }
10+ < ul className = 'list-group' >
11+ { items . map ( items => < li className = 'list-group-item' key = { items . id } > { items . title } </ li > ) }
1412 </ ul >
1513 ) ;
1614}
Original file line number Diff line number Diff line change @@ -4,16 +4,16 @@ import Reminder from '../models/reminder';
44
55class ReminderServices {
66 http = axios . create ( {
7- baseURL : 'https://jsonplaceholder.typicode.com'
7+ baseURL : 'https://jsonplaceholder.typicode.com/ '
88 } ) ;
99
1010 async getReminder ( ) {
11- const response = await this . http . get < Reminder [ ] > ( '/todo ' ) ;
11+ const response = await this . http . get < Reminder [ ] > ( '/todos ' ) ;
1212 return response . data
1313 }
1414
1515 async addReminder ( title : string ) {
16- const response = await this . http . post < Reminder [ ] > ( '/todo ' , { title } ) ;
16+ const response = await this . http . post < Reminder > ( '/todos ' , { title } ) ;
1717 return response . data
1818 }
1919
You can’t perform that action at this time.
0 commit comments