File tree Expand file tree Collapse file tree 3 files changed +3
-20
lines changed
advanced-hooks/05-form-actions/lecture Expand file tree Collapse file tree 3 files changed +3
-20
lines changed Original file line number Diff line number Diff line change @@ -41,21 +41,6 @@ export function App() {
4141 const [ messages , setMessages ] = useState < Message [ ] > ( [ ] )
4242 const [ pending , setPending ] = useState ( false )
4343
44- // // 1. Making this an async function makes little difference
45- // // 2. However, setting messages state with the fn approach
46- // // fixes the fact that messages were being overridden
47- // async function handleSubmit(e: FormEvent<HTMLFormElement>) {
48- // e.preventDefault()
49- // setPending(true)
50- // const formData = new FormData(e.currentTarget)
51- // messageRef.current.value = ''
52- // messageRef.current.focus()
53- // const res = await addMessage(formData.get('messageText') as string)
54- // const { message: newMessage } = await res.json()
55- // setMessages((messages) => messages.concat(newMessage))
56- // setPending(false)
57- // }
58-
5944 function handleSubmit ( e : FormEvent < HTMLFormElement > ) {
6045 e . preventDefault ( )
6146 setPending ( true )
Original file line number Diff line number Diff line change @@ -3,9 +3,6 @@ import * as ReactDOM from 'react-dom/client'
33import { LessonBody , LessonCard } from '~/Lesson'
44import { Counter } from './Counter'
55
6- // A nice visual explanation of keys
7- // https://twitter.com/dan_abramov/status/1415279090446204929
8-
96function App ( ) {
107 const vacations = [
118 { id : 1 , name : 'Maui' , hotels : 5 } ,
@@ -15,8 +12,7 @@ function App() {
1512 { id : 5 , name : 'Florida Keys' , hotels : 1 } ,
1613 ]
1714
18- // Do "reduce" for total hotels
19- const totalHotels = 16
15+ const totalHotels = vacations . reduce ( ( sum , item ) => sum + item . hotels , 0 )
2016
2117 return (
2218 < LessonBody >
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ export function App() {
1111 useState ( /* initialState */ )
1212
1313 function loadVacations ( ) {
14+ // The getAll() method will resolve an array of vacations. We nest our network API calls
15+ // in objects like api.vacations.getAll() for convenience.
1416 api . vacations . getAll ( ) . then ( ( vacations ) => {
1517 console . log ( vacations )
1618 } )
You can’t perform that action at this time.
0 commit comments