File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "cSpell.words" : [
3+ " miscfeat" ,
34 " noopener" ,
45 " noreferrer" ,
56 " samplereact" ,
Original file line number Diff line number Diff line change 33import { useState } from 'react' ;
44
55export default function MiscFeat ( ) {
6- const [ days , setDays ] = useState ( '' ) ;
6+ const [ days , setDays ] = useState ( 0 ) ;
7+ const [ daysAfterNow , setDaysAfterNow ] = useState ( '' ) ;
78
89 function handleDaysChange ( e ) {
910 setDays ( e . target . value ) ;
1011 }
1112
12- async function handleSubmit ( e ) {
13+ async function handleSubmitDaysAfterNow ( e ) {
1314 e . preventDefault ( ) ;
15+ const rsp = await fetch ( `/api/miscfeat/daysAfterNow?days=${ days } ` ) ;
16+ const res = await rsp . json ( )
17+ setDaysAfterNow ( new Date ( res . theTime ) . toString ( ) ) ;
1418 }
1519
1620 return (
1721 < main className = "flex min-h-screen flex-col items-center justify-between p-24" >
18- < form onSubmit = { handleSubmit } className = "grid grid-cols-[1fr_3fr] gap-4" >
22+ < form onSubmit = { handleSubmitDaysAfterNow } className = "grid grid-cols-[1fr_3fr] gap-4 place-items-center justify-items-stretch " >
1923 < label htmlFor = 'txtDays' > Days:</ label >
2024 < input id = 'txtDays' type = "text" value = { days } onChange = { handleDaysChange } />
2125 < button className = "col-start-2 py-2 px-4 bg-blue-500 text-white font-semibold rounded-lg shadow-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:ring-opacity-75" > Days After Now</ button >
26+ < label htmlFor = 'txtDaysAfterNow' > Result:</ label >
27+ < input type = "text" id = 'txtDaysAfterNow' value = { daysAfterNow } readOnly />
2228 </ form >
2329 </ main >
2430 )
You can’t perform that action at this time.
0 commit comments