添加react-redux、redux

This commit is contained in:
waliang.wang 2017-07-09 21:33:21 +08:00
parent 7dfb9489cb
commit 68dd0b4c96
9 changed files with 86 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import React, { Component } from 'react'
import './store.js'
import Routes from './routes'
class App extends Component {

5
client/ReduxContainer.js Normal file
View File

@ -0,0 +1,5 @@
import LoginRedux from './containers/Login/Login_redux.js'
export default {
LoginRedux
}

View File

@ -10,8 +10,10 @@ class Login extends Component {
}
render () {
console.log(this.props)
return (
<acticle className="login-main">
<span>{this.props.value}{this.props.per}</span>
<section className="login-box">
<div className="content">
<Input

View File

@ -0,0 +1,27 @@
import React, { Component } from 'react'
import { createStore, combineReducers } from 'redux'
import { connect } from 'react-redux'
import Login from './Login.js'
// Action
const increaseAction = { type: 'increase' }
function mapStateToProps(state) {
return {
per: '测试数据',
}
}
function mapDispatchToProps(dispatch) {
return {
onIncreaseClick: () => dispatch(increaseAction)
}
}
const App = connect(
mapStateToProps,
mapDispatchToProps
)(Login)
export default App

View File

@ -0,0 +1,11 @@
import React, { Component } from 'react'
export default function (state = 3, action) {
const count = state
switch (action.type) {
case 'increasec':
return count + 1
default:
return state
}
}

View File

@ -1,5 +1,5 @@
import Home from './Home/Home.js'
import Login from './Login/Login.js'
import Login from './Login/Login_container.js'
import ProjectGroups from './ProjectGroups/ProjectGroups.js'
export {

View File

@ -1,8 +1,16 @@
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import { createStore, combineReducers } from 'redux'
import { Provider, connect } from 'react-redux'
import ReduxContainer from './redux.js'
// 合并 redux 创建stroe
const store = createStore(combineReducers( ReduxContainer ))
ReactDOM.render(
<App />,
<Provider store={store}>
<App />
</Provider>,
document.getElementById('yapi')
)
)

28
client/store.js Normal file
View File

@ -0,0 +1,28 @@
import React, { Component } from 'react'
import { createStore, combineReducers } from 'redux'
import Login from './containers/Login/Login_redux.js'
import { Provider, connect } from 'react-redux'
// const store = createStore(combineReducers({Login}))
// const increaseAction = { type: 'increase' }
// function mapStateToProps(state) {
// return {
// value: 4444,
// per: 4444444,
// }
// }
// function mapDispatchToProps(dispatch) {
// return {
// onIncreaseClick: () => dispatch()
// }
// }
// const App = connect(
// mapStateToProps,
// mapDispatchToProps
// )(Login)
// export { store }

View File

@ -27,6 +27,7 @@
"mongoose": "4.10.8",
"mongoose-auto-increment": "^5.0.1",
"node-sass-china": "^4.5.0",
"redux": "^3.7.1",
"ykit-config-antd": "^0.1.3",
"ykit-config-react": "^0.4.4"
},