Skip to content

Commit b4c4143

Browse files
committed
update react-redux
1 parent 2e175af commit b4c4143

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/page/Counter/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { connect } from 'react-redux';
22
import Counter from './UI/index';
33

44
const mapStateToProps = (state, ownProps) => {
5-
console.log('mapStateToProps', state.count,ownProps);
5+
// console.log('mapStateToProps', state.count,ownProps);
66
return {
77
value: state.count
88
}

src/page/reducer/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
const reducer = (state = { count: 0 }, action) => {
33
switch (action.type) {
44
case 'increase':
5-
return { count: state.count + 1 }
5+
return { count: state.count + 1 };
66
case 'decrease':
7-
return { count: state.count - 1 }
7+
return { count: state.count - 1 };
88
default:
9-
return state
9+
return state;
1010
}
11-
}
12-
export default reducer;
11+
};
12+
export default reducer;

src/router/index.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1-
import React from "react";
1+
import React, { useState, useEffect } from "react";
22
import { HashRouter ,BrowserRouter, Route, Link,Switch } from "react-router-dom";
33
import Home from '../page/CssTest/index'
44
import Counter from '../page/Counter/index'
5+
import { connect } from 'react-redux';
56

67

7-
function App() {
8+
function mapStateToProps(state) {
9+
return {
10+
num: state.count,
11+
};
12+
}
13+
function App({num}) {
14+
const [count, setCount] = useState(0);
15+
console.log('222222', num);
16+
useEffect(() => {
17+
console.log('111111111' , num);
18+
}, [num]);
819
return (
920
<HashRouter>
1021
<div>
1122
<Header />
23+
<div>
24+
test---
25+
{num}
26+
</div>
1227
<div>
1328
<Route exact path="/" component={Home} />
1429
<Route path="/about" component={About} />
@@ -78,4 +93,4 @@ function Header() {
7893
);
7994
}
8095

81-
export default App;
96+
export default connect(mapStateToProps)(App);

0 commit comments

Comments
 (0)