import React from 'react'
import {connect} from 'react-redux'
import {add,reduce,addAsync} from './index.redux'
class App extends React.Component {
// constructor() {
//
// }
render(){
const num = this.props.num
const add = this.props.add
const reduce = this.props.reduce
const addAsync = this.props.addAsync
return(
<div>
<h1>展示dedux数据{num}</h1>
<button onClick={add}>➕加1</button>
<button onClick={reduce}>➖减1</button>
<button onClick={addAsync}>➕加1(两秒以后)</button>
</div>
)
}
}
const mapStatetoProps = (state) => {
return {num:state}
}
const acitonCreators = {add,reduce,addAsync}
App = connect(mapStatetoProps,acitonCreators)(App)
export default App
import React from 'react'
import {connect} from 'react-redux'
import {add,reduce,addAsync} from './index.redux'
@connect(
// 你要state什么属性放到props
(state) => {
return {num:state}},
{add,reduce,addAsync}
)
class App extends React.Component {
// constructor() {
//
// }
render(){
const num = this.props.num
const add = this.props.add
const reduce = this.props.reduce
const addAsync = this.props.addAsync
return(
<div>
<h1>展示dedux数据{num}</h1>
<button onClick={add}>➕加1</button>
<button onClick={reduce}>➖减1</button>
<button onClick={addAsync}>➕加1(两秒以后)</button>
</div>
)
}
}
export default App
import React from 'react'
import ReactDom from 'react-dom'
import thunk from 'redux-thunk'
import {Provider} from 'react-redux'
import {createStore, applyMiddleware ,compose} from 'redux'
import {counter} from './index.redux'
import App from './App'
const store = createStore(counter,compose(
applyMiddleware(thunk),
window.devToolsExtension ? window.devToolsExtension():()=>{}
))
ReactDom.render(
(<Provider store={store}>
<App/>
</Provider>),
document.getElementById('root')
);