实操《深入浅出React和Redux》第一期
发布时间:2020-12-15 06:38:57 所属栏目:百科 来源:网络整理
导读:上次的书看得差不多了,但实践越来越麻烦。 于是重新开一本书,这次,人家用了create-react-app。 实践方面就容易开展啦。:) 我有几张阿里云幸运券分享给你,用券购买或者升级阿里云相应产品会有特惠惊喜哦!把想要买的产品的幸运券都领走吧!快下手,马上
上次的书看得差不多了,但实践越来越麻烦。 于是重新开一本书,这次,人家用了create-react-app。 实践方面就容易开展啦。:) 我有几张阿里云幸运券分享给你,用券购买或者升级阿里云相应产品会有特惠惊喜哦!把想要买的产品的幸运券都领走吧!快下手,马上就要抢光了。 主要文件内容也少多啦。 index.js import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; import ControlPanel from './ControlPanel'; import registerServiceWorker from './registerServiceWorker'; ReactDOM.render(<ControlPanel />,document.getElementById('root')); registerServiceWorker(); ControlPanel.js import React,{ Component } from 'react'; import Counter from './Counter'; const style = { margin: '20px' }; class ControlPanel extends Component { constructor(props){ super(props); this.onCounterUpdate = this.onCounterUpdate.bind(this); this.initValue = [0,10,20]; const initSum = this.initValue.reduce((a,b) => a+b,0); this.state = { sum: initSum }; } onCounterUpdate(newValue,previousValue) { const valueChange = newValue - previousValue; this.setState({sum: this.state.sum + valueChange}); } render() { console.log("enter ControlPanel render"); return ( <div style={style}> <Counter onUpdate={this.onCounterUpdate} caption="First" /> <Counter onUpdate={this.onCounterUpdate} caption="Second" initValue = {10} /> <Counter onUpdate={this.onCounterUpdate} caption="Third" initValue = {20} /> <button onClick={ ()=> this.forceUpdate() }> Click me to re-render! </button> <hr /> <div> Total Count: {this.state.sum}</div> </div> ); } } export default ControlPanel;
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- c# – 使用Entity Framework时,存储库应该是工作单元的属性
- c# – CSHTML / Razor Views的文档
- 北京源创会 Oracle 首席工程师将剖析 Java 9 模块化
- flex currenTarget与 target 的区别
- 解决Compiling Ribbon.xml 问题
- reactjs – 如何配置ESLint在Atom编辑器上的反应
- swift 中通过AVFoundation来定制拍摄窗口
- ruby-on-rails – Rails accepted_nested_attributes_for回
- flex偶尔监听不到事件的原因
- 用jaxb方法将xml(带命名空间xmlns)转为java实体类