|
1 |
| -import React from "react"; |
2 |
| -import { view, store } from "react-easy-state"; |
3 |
| -import Card from "@material-ui/core/Card"; |
4 |
| -import CardMedia from "@material-ui/core/CardMedia"; |
5 |
| -import CardContent from "@material-ui/core/CardContent"; |
| 1 | +import React from 'react'; |
| 2 | +import { view, store } from 'react-easy-state'; |
| 3 | +import Card from '@material-ui/core/Card'; |
| 4 | +import CardMedia from '@material-ui/core/CardMedia'; |
| 5 | +import CardContent from '@material-ui/core/CardContent'; |
6 | 6 |
|
7 | 7 | // this is re-rendered whenever the relevant parts of the used data stores change
|
8 |
| -export default view( |
9 |
| - ({ name, description, image_url: imageUrl, food_pairing: foodPairing }) => { |
10 |
| - const beer = store({ details: false }); |
| 8 | +const Beer = ({ |
| 9 | + name, |
| 10 | + description, |
| 11 | + image_url: imageUrl, |
| 12 | + food_pairing: foodPairing, |
| 13 | +}) => { |
| 14 | + const beer = store({ details: false }); |
11 | 15 |
|
12 |
| - return ( |
13 |
| - <Card onClick={() => (beer.details = !beer.details)} className="beer"> |
14 |
| - {!beer.details && <CardMedia image={imageUrl} className="media" />} |
15 |
| - <CardContent> |
16 |
| - <h3>{name}</h3> |
17 |
| - {beer.details ? ( |
18 |
| - <p>{description}</p> |
19 |
| - ) : ( |
20 |
| - <ul> |
21 |
| - {foodPairing.map(food => ( |
22 |
| - <li key={food}>{food}</li> |
23 |
| - ))} |
24 |
| - </ul> |
25 |
| - )} |
26 |
| - </CardContent> |
27 |
| - </Card> |
28 |
| - ); |
29 |
| - } |
30 |
| -); |
| 16 | + return ( |
| 17 | + <Card |
| 18 | + onClick={() => { |
| 19 | + beer.details = !beer.details; |
| 20 | + }} |
| 21 | + className="beer" |
| 22 | + > |
| 23 | + {!beer.details && ( |
| 24 | + <CardMedia image={imageUrl} className="media" /> |
| 25 | + )} |
| 26 | + <CardContent> |
| 27 | + <h3>{name}</h3> |
| 28 | + {beer.details ? ( |
| 29 | + <p>{description}</p> |
| 30 | + ) : ( |
| 31 | + <ul> |
| 32 | + {foodPairing.map(food => ( |
| 33 | + <li key={food}>{food}</li> |
| 34 | + ))} |
| 35 | + </ul> |
| 36 | + )} |
| 37 | + </CardContent> |
| 38 | + </Card> |
| 39 | + ); |
| 40 | +}; |
| 41 | + |
| 42 | +export default view(Beer); |
0 commit comments