File tree 1 file changed +24
-2
lines changed
1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,20 @@ export class Practice extends React.Component {
10
10
this . setState ( state => ( { isFront : ! state . isFront } ) )
11
11
}
12
12
13
+ handleNextCard = ( ) => {
14
+ const { cards } = this . props
15
+ this . setState ( state => ( {
16
+ currentIndex : ( state . currentIndex + 1 ) % cards . length
17
+ } ) )
18
+ }
19
+
20
+ handlePrevCard = ( ) => {
21
+ const { cards } = this . props
22
+ this . setState ( state => ( {
23
+ currentIndex : ( state . currentIndex - 1 + cards . length ) % cards . length
24
+ } ) )
25
+ }
26
+
13
27
render ( ) {
14
28
const { cards } = this . props
15
29
const { currentIndex, isFront } = this . state
@@ -32,10 +46,18 @@ export class Practice extends React.Component {
32
46
{ isFront ? 'show back' : 'show front' }
33
47
</ button >
34
48
< div >
35
- < button type = "button" className = "secondary" >
49
+ < button
50
+ type = "button"
51
+ className = "secondary"
52
+ onClick = { this . handlePrevCard }
53
+ >
36
54
previous
37
55
</ button >
38
- < button type = "button" className = "primary" >
56
+ < button
57
+ type = "button"
58
+ className = "primary"
59
+ onClick = { this . handleNextCard }
60
+ >
39
61
next
40
62
</ button >
41
63
</ div >
You can’t perform that action at this time.
0 commit comments