File tree Expand file tree Collapse file tree 3 files changed +25
-13
lines changed Expand file tree Collapse file tree 3 files changed +25
-13
lines changed Original file line number Diff line number Diff line change
1
+ "use server" ;
2
+
3
+ export default async function createAnswer ( formData : FormData ) {
4
+ const rawFormData = {
5
+ radio : formData . get ( "radio-0" ) ,
6
+ } ;
7
+ // Test it out:
8
+ console . log ( rawFormData ) ;
9
+ }
Original file line number Diff line number Diff line change
1
+ import createAnswer from "~~/app/lib/actions" ;
1
2
import { Question } from "~~/app/lib/definitions" ;
2
3
3
4
export default function VotingForm ( { question } : { question : Question } ) {
4
5
return (
5
- < div className = "items-left mb-4" >
6
- < div > { question . question } </ div >
7
- { question . choices_array . map ( choice => (
8
- < div className = "flex items-center mb-4" key = { choice } >
9
- < label className = "label cursor-pointer ms-2" >
10
- < input type = "radio" name = "radio-10" className = "radio checked:bg-red-500" />
11
- < span className = "ms-2" > { choice } </ span >
12
- </ label >
13
- </ div >
14
- ) ) }
15
- < button className = "bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 m-4 rounded" > Submit</ button >
16
- </ div >
6
+ < form action = { createAnswer } >
7
+ < div className = "items-left m-8" >
8
+ < div > { question . question } </ div >
9
+ { question . choices_array . map ( choice => (
10
+ < div className = "flex items-center mb-4" key = { choice } >
11
+ < label className = "label cursor-pointer ms-2" >
12
+ < input type = "radio" name = "radio-0" value = { choice } className = "radio checked:bg-red-500" />
13
+ < span className = "ms-2" > { choice } </ span >
14
+ </ label >
15
+ </ div >
16
+ ) ) }
17
+ < button className = "bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 m-4 rounded" > Submit</ button >
18
+ </ div >
19
+ </ form >
17
20
) ;
18
21
}
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ export default async function Page() {
5
5
const questions = await fetchQuestions ( ) ;
6
6
return (
7
7
< >
8
- < VotingForm question = { questions [ 0 ] } />
8
+ < VotingForm question = { questions [ 2 ] } />
9
9
</ >
10
10
) ;
11
11
}
You can’t perform that action at this time.
0 commit comments