1import React from "react";
2import { useDispatch, useSelector } from "react-redux";
3import { addCount } from "./store/counter/actions";
4
5export const Count = () => {
6 const count = useSelector(state => state.counter.count);
7 const dispatch = useDispatch();
8
9 return (
10 <main>
11 <div>Count: {count}</div>
12 <button onClick={() => dispatch(addCount())}>Add to count</button>
13 </main>
14 );
15};
16
1import React from "react";
2import { connect } from "react-redux";
3import { addCount } from "./store/counter/actions";
4
5export const Count = ({ count, addCount }) => {
6 return (
7 <main>
8 <div>Count: {count}</div>
9 <button onClick={addCount}>Add to count</button>
10 </main>
11 );
12};
13
14const mapStateToProps = state => ({
15 count: state.counter.count
16});
17
18const mapDispatchToProps = { addCount };
19
20export default connect(mapStateToProps, mapDispatchToProps)(Count);
21