Ich versuche Zustandswert zu erhöhen und verringern in reagieren mit react-redux
.Ich Aktionen hinzufügen, Behälter, Druckminderer .Aber ich weiß nicht, wie die increment
und decrement
Aktion hier abonnieren ist mein CodeWie erhöht oder dekrementiert man den Statuswert in react?
Ich möchte erhöhen und verringern den Wert, wenn der Benutzer klicken Sie auf Tasten
hier mein Code http://codepen.io/anon/pen/jVjMXv?editors=1010
const abc= (state=0,action) => {
console.log(action.type)
switch(action.type){
case 'INCREMENT':
return state +1
case 'DECREMENT':
return state -1
Default :
return state;
}
}
const {createStore,bindActionCreators} =Redux;
const {Provider,connect} =ReactRedux;
const store = createStore(abc);
class First extends React.Component {
constructor(){
super();
this.state ={
digit :0
}
}
inc(){
console.log('ince')
}
dec(){
console.log('dec')
}
render(){
return (
<div>
<button onClick={this.inc.bind(this)}>INCREMENT</button>
<p>{this.state.digit}</p>
<button onClick={this.dec.bind(this)}>DECREMENT</button>
</div>
)
}
}
const actions = {
increment:() => {
return {
type: 'INCREMENT',
}
},
decrement:() => {
return {
type: 'DECREMENT',
}
}
};
const AppContainer = connect(
function mapStateToProps(state) {
return {
digit: state
};
},
function mapDispatchToProps(dispatch) {
return bindActionCreators(actions, dispatch);
}
)(First);
ReactDOM.render(
<Provider store={store}>
<First/>
</Provider>
,document.getElementById('root'))
Ich bin nicht klar mit 'First' und' Third'? – user5711656
warum render 'containers' ... also wenn ich zwei Komponenten '(first, second)' habe, die jeweils individuelle Container haben ('AppContainer1',' AppContainer2') ..so füge ich Container in render Methode hinzu ?? oder nur Komponente? – user5711656
dritten Punkt ist klar ..Ich habe nur Frage in 'First' Punkt – user5711656