Say I have a simple toggle:
When I click the button, the Color component changes between red and blue
I might achieve this result by doing something like this.
index.js
Button: onClick={()=>{dispatch(changeColor())}}
Color: this.props.color ? blue : red
container.js
connect(mapStateToProps)(indexPage)
action_creator.js
function changeColor(){
return {type: 'CHANGE_COLOR'}
}
reducer.js
switch(){
case 'CHANGE_COLOR':
return {color: true}
but this is a hell of a lot of code to write for something that I could have achieved in 5 seconds with jQuery, some classes, and some css...
So I guess what I'm really asking is, what am I doing wrong here?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…