File tree Expand file tree Collapse file tree 1 file changed +29
-13
lines changed
steps/03-state-and-clicks/src/components Expand file tree Collapse file tree 1 file changed +29
-13
lines changed Original file line number Diff line number Diff line change 1+ import React from 'react' ;
12import { ArrowBack , ArrowForward } from '@mui/icons-material' ;
23import MuiFab from '@mui/material/Fab' ;
34import { PersonCard } from './PersonCard' ;
@@ -6,17 +7,32 @@ interface CarouselProps {
67 people : People ;
78}
89
9- export function Carousel ( { people } : CarouselProps ) {
10- const randomPerson = people [ Math . floor ( Math . random ( ) * people . length ) ] ;
11- return (
12- < section className = "carousel" >
13- < MuiFab size = "medium" color = "default" aria-label = "previous" >
14- < ArrowBack />
15- </ MuiFab >
16- < PersonCard person = { randomPerson } />
17- < MuiFab size = "medium" color = "default" aria-label = "previous" >
18- < ArrowForward />
19- </ MuiFab >
20- </ section >
21- ) ;
10+ interface CarouselState {
11+ randomPersonIndex : number ;
12+ }
13+
14+ export class Carousel extends React . Component < CarouselProps , CarouselState > {
15+ constructor ( props : CarouselProps ) {
16+ super ( props ) ;
17+ this . state = {
18+ randomPersonIndex : Math . floor ( Math . random ( ) * props . people . length ) ,
19+ } ;
20+ }
21+
22+ render ( ) {
23+ const { people } = this . props ;
24+ const randomPerson = people [ this . state . randomPersonIndex ] ;
25+
26+ return (
27+ < section className = "carousel" >
28+ < MuiFab size = "medium" color = "default" aria-label = "previous" >
29+ < ArrowBack />
30+ </ MuiFab >
31+ < PersonCard person = { randomPerson } />
32+ < MuiFab size = "medium" color = "default" aria-label = "next" >
33+ < ArrowForward />
34+ </ MuiFab >
35+ </ section >
36+ ) ;
37+ }
2238}
You can’t perform that action at this time.
0 commit comments