-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (33 loc) · 866 Bytes
/
index.js
File metadata and controls
38 lines (33 loc) · 866 Bytes
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
import React from "react";
import ReactDOM from "react-dom";
import { createStore } from "redux";
const counterReducer = (state = 0, action) => {
switch (action.type) {
case "INCREMENT":
return state + 1;
case "DECREMENT":
return state - 1;
case "ZERO":
return 0;
default:
return state;
}
};
const store = createStore(counterReducer);
const App = () => {
return (
<div>
<div>{store.getState()}</div>
<button onClick={e => store.dispatch({ type: "INCREMENT" })}>plus</button>
<button onClick={e => store.dispatch({ type: "DECREMENT" })}>
minus
</button>
<button onClick={e => store.dispatch({ type: "ZERO" })}>zero</button>
</div>
);
};
const renderApp = () => {
ReactDOM.render(<App />, document.getElementById("root"));
};
renderApp();
store.subscribe(renderApp);