Redux 结合React
index.js
index.jsimport React from 'react'
import ReactDom from 'react-dom'
import {createStore} from 'redux'
import {counter} from './index.redux'
import App from './App'
const store = createStore(counter)
function render() {
ReactDom.render(<App store={store} />,document.getElementById('root'));
}
render();
store.subscribe(render)App.jsx
App.jsximport React from 'react'
import {add} from './index.redux'
class App extends React.Component {
render(){
const store = this.props.store
const num = store.getState()
return(
<div>
<h1>展示dedux数据{num}</h1>
<button onClick={()=>store.dispatch(add())}>➕加1</button>
</div>
)
}
}
export default Appindex.redux.js
index.redux.js最后更新于