forked from rjperkins/redux-hooks-counter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (36 loc) · 971 Bytes
/
index.js
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
import React from "react";
import ReactDOM from "react-dom";
import { createStore } from "redux";
import { Provider, useSelector, useDispatch } from "react-redux";
import reducer from "./reducer.js";
const store = createStore(reducer);
function Counter(props) {
const counter = useSelector(function(state) {
return state.counter;
});
const dispatch = useDispatch();
return (
<div>
<button onClick={() => dispatch({ type: "INCREMENT" })}>Increment</button>
<Button text={`the current counter is ${counter}`}></Button>
<button onClick={() => dispatch({ type: "DECREMENT" })}>Decrement</button>
</div>
);
}
function Clicks(props) {
const clicked = useSelector(function(state) {
return state.clicked;
});
return (
<div>
<p>You have clicked: {clicked} times.</p>
</div>
);
}
ReactDOM.render(
<Provider store={store}>
<Counter />
<Clicks />
</Provider>,
document.getElementById("root")
);