今天开始学习React,todo-list的实现、项目初始化、react-redux的使用
2018-12-29 11:26
756 查看
[code]class Todo extends React.Component { constructor(props) { super(props) this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this) this.state = { list: [] } } handleKeyUp(e) { if (e.keyCode === 13) { this.setState({ list: [...this.state.list, e.target.value] }) e.target.value = '' } } handleClick(index, e) { this.setState({ list: [...this.state.list.slice(0, index), ...this.state.list.slice(index + 1)] }) } render() { return (<div> <div className='todo-warpper'> <input className='todo-input' onKeyUp={this.handleKeyUp.bind(this)}/> </div> <ul className='todo-list'> {(this.state.list || []).map((item, index) => <li onClick={this.handleClick.bind(this, index)} key={index}>{item}</li>) } </ul> </div>) } } ReactDOM.render( <Todo/>, document.getElementById('root'));
(1)react项目的初始化:
npm install -g create-react-app
create-react-app 项目名称
npm install react-redux redux
(2)项目结构:
actions--->用户行为
components--->组件
containers--->容器
reducer---> store里面负责分发action行为
index.html ---> 模板文件
server.js---> 构建项目相关配置文件
webpack---> 打包配置文件
(3)react-redux
智能组件和木偶组件:
相关文章推荐
- 从今天开始学习iOS开发(iOS 7版)--实现一款App之使用设计模式
- 从今天开始学习iOS开发(iOS 7版)--实现一款App之Foundation框架的使用
- 从今天开始学习iOS开发(iOS 7版)--实现一款App之Foundation框架的使用
- 开始cocos2dx学习小记:MacOS下使用cocos2dx创建项目遇到permission denied
- 从今天开始学习iOS开发(iOS 7版)--实现一款App-教程:添加数据
- React-Native新列表组件FlatList和SectionList学习 | | 联动列表实现
- Ant学习---第三节:使用Ant实现一个最小的项目编译
- 今天开始使用unity 5.3 进行学习编程
- 如何优雅地在React项目中使用Redux
- Android使用局和数据实现天气项目-android学习之旅(十二)
- 【Android开源项目解析】QQ“一键下班”功能实现解析——学习Path及贝塞尔曲线的基本使用
- 开始cocos2dx学习小记:MacOS下使用cocos2dx创建项目遇到permission denied
- React-Native新列表组件FlatList和SectionList学习 | | 联动列表实现
- 在什么情况需要对特征使用归一化处理?--从机器学习项目中开始学习
- react 脚手架 ------create-react-app初始化项目 --yarn 使用
- 从今天开始使用csdn的blog开始记录学习历程
- JAVA学习--ArrayList使用方法:List的主要实现类
- 从今天开始学习iOS开发(iOS 7版)--实现一款App之合并数据
- 小白学习做项目(1)_使用EntityFramework实现Code First设计数据库(1)
- [Redux] React Todo List Example (Toggling a Todo)