Closed raza2022 closed 7 years ago
Hey @raza2022, do you have a container to connect the component to your redux store? What type of error are you getting?
@andytango Thanks i just updated the state and it working fine, does it means component render only on state change not on props? here is my updated code for Counter.js
in components
may help some nob like me :)
class Counter extends React.Component {
constructor() {
super();
this.state = {
counter: 0
}
}
increment() {
this.props.store.dispatch({
type: 'ADD_ITEM'
});
this.setState({counter: this.props.store.getState().counter})
}
decrement() {
this.props.store.dispatch({
type: 'REMOVE_ITEM'
});
this.setState({counter: this.props.store.getState().counter})
}
render() {
let counter = this.state.counter;
return (
<div className="counter-component" styleName="counter-component">
<h3>the counter should be updated</h3>
<h1>{counter}</h1>
<button className="btn" styleName="counter-btn" onClick={this.increment.bind(this)}>+</button>
<button className="btn" styleName="counter-btn" onClick={this.decrement.bind(this)}>-</button>
</div>
);
}
}
@stylesuxx Thanks for the great work I have a issue with combined reducers, that is not working my state. for simplicity i just replaced my complex example with the basic counter example given every where. so my code look like
counter.js
and here is the
reducers.js
and here is my full code of
Counter.js
incomponents