说我有一个简单的切换:
单击按钮时,"颜色"组件在红色和蓝色之间变化
通过做这样的事情,我可能会达到这个结果.
index.js
Button: onClick={()=>{dispatch(changeColor())}}
Color: this.props.color ? blue : red
Run Code Online (Sandbox Code Playgroud)
container.js
connect(mapStateToProps)(indexPage)
Run Code Online (Sandbox Code Playgroud)
action_creator.js
function changeColor(){
return {type: 'CHANGE_COLOR'}
}
Run Code Online (Sandbox Code Playgroud)
reducer.js
switch(){
case 'CHANGE_COLOR':
return {color: true}
Run Code Online (Sandbox Code Playgroud)
但这是一个很多代码的地狱,我可以用jQuery,一些类和一些css在5秒内完成一些代码.
所以我想我真正想问的是,我在这里做错了什么?