-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStretch.jsx
53 lines (47 loc) · 1.28 KB
/
Stretch.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React, { useState } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { addFavorite } from '../actions/userActions';
const Stretch = ({ name, equipment, difficulty, instructions }) => {
const user = useSelector((state) => state.userLogin);
const favs = useSelector((state) => state.favorites);
const dispatch = useDispatch();
const [added, setAdded] = useState(false);
const addToFavorites = () => {
setAdded(true);
dispatch(
addFavorite(
user.userInfo.userDetail.email,
name,
equipment,
difficulty,
instructions
)
);
};
// insert any logic for the Stretch here
// return stretch component with passed-in props from query to server
return (
<div className='stretchComp'>
<h3>{name}</h3>
<ul>
<li>
<strong>Equipment:</strong> {equipment}
</li>
<li>
<strong>Difficulty:</strong> {difficulty}
</li>
<li>
<strong>Instructions:</strong> {instructions}
</li>
</ul>
{!added ? (
<button className={'faveButton'} onClick={addToFavorites}>
Add to Favorites
</button>
) : (
<h2>Already In Favorites</h2>
)}
</div>
);
};
export default Stretch;