项目环境搭建

  使用create-react-app

CSS使用styled-components

  yarn add styled-components

引入reset.css样式

  import { createGlobalStyle } from 'styled-components'

  export const GlobalStyle = createGlobalStyle ` `
  然后在App.js中引入GlibalStyle组件
引入iconfont
  配置跟reset.css一样
引入react-transition-group
   实现组件动画效果
引入redux  react-redux
  如何配置 首先创建store 文件夹   index.js   reducer.js只一个纯函数
  然后App.js引入Provider  store
  接着在组件中使用connect做连接    connect(mapStateToProps, mapDispathcToProps)(Header)
使用redux-devtool-extension插件
  https://github.com/zalmoxisus/redux-devtools-extension
  如何使用 
  import { createStore, applyMiddleware, compose } from 'redux';

+ const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
+ const store = createStore(reducer, /* preloadedState, */ composeEnhancers(
- const store = createStore(reducer, /* preloadedState, */ compose(
applyMiddleware(...middleware)
));

使用combineReducer对reducer拆分

  修改store下的reducer.js代码

import { combineReducers } from 'redux'
import { reducer as headerReducer} from '../components/header/store' export default combineReducers({
header: headerReducer
})

使用actionCreators.js和actionTypes.js对store代码优化

使用immutable.js和redux-immutable

  yarn add redux-immutable

  生成的immutable对象,改对象不可改变

  yarn add immutable

  如何使用

import {fromJS} from 'immutable'

const defaultState = fromJS({
focused: false
})
const mapStateToProps = state => {
return {
focused:state.header.get('focused')
}
}
export default (state = defaultState, action) => {
if (action.type === actionTypes.SEARCH_BLUR) {
return state.set('focused', false)
}
if (action.type === actionTypes.SEARCH_FOCUS) {
return state.set('focused', true)
}
return state
}

使用redux-thunk

  异步操作不在componentDidMount中操作

  放到action

  yarn add redux-thunk

后端使用koa koa-router  koa-cors mock

  模拟后端服务器

前端使用axios

  跨域配置  "proxy": "http://localhost:8080"

安装react-router-dom  

  import {BrowserRouter, Route} from 'react-router-dom'

  <BrowserRouter>
    <div>
      <Header/>
      <Route path="/" exact component={Home}/>
      <Route path="/detail/:id" exact component={Detail}/>
    </div>
  </BrowserRouter>

  获得pathname

    const {pathname} = this.props.location

  页面跳转

    this.props.history.push('/')

  页面重定向

    <Redirect from='/...' to='/...' />

React开发笔记的更多相关文章

  1. React Native 开发笔记

    ReactNativeDemo 学习ReactNative开发,搭建ReactNative第一个项目 React Native 开发笔记 1.安装Homebrew $ /usr/bin/ruby -e ...

  2. Webpack笔记(二)——搭建React开发环境

    前几天一直在学习webpack,总算比之前学习的时候有了点收获,所以在昨天发布了一篇webpack入门笔记,今天继续使用webpack练了练手,搭建了一个React开发环境,如果还不熟悉的童鞋可以看一 ...

  3. react学习笔记(一)用create-react-app构建 React 开发环境

    React 可以高效.灵活的用来构建用户界面框架,react利用高效的算法最小化重绘DOM. create-react-app 是来自于 Facebook,通过该命令不需配置就能快速构建 React ...

  4. React笔记01——React开发环境准备

    1 React简介 2013年由Facebook推出,代码开源,函数式编程.目前使用人数最多的前端框架.健全的文档与完善的社区. 官网:reactjs.org 阅读文档:官网中的Docs React ...

  5. React学习笔记--程序调试

    React学习笔记 二 程序调试   前面我们搭建好了React的基本开发环境,可以编写基本的React js程序了.但完成的开发环境肯定包含调试器,怎么调试用React编写的JS程序呢?有浏览器,比 ...

  6. react系列笔记1 用npx npm命令创建react app

    react系列笔记1 用npx npm命令创建react app create-react-app my-app是开始构建新的 React 单页应用程序的最佳方式.它已经为你设置好了开发环境,以便您可 ...

  7. React学习笔记 - Hello World

    React Learn Note 1 React学习笔记(一) 标签(空格分隔): React JavaScript 前.Hello World 1. 创建单页面应用 使用Create React A ...

  8. react自学笔记总结不间断更新

    React React 是由Facfbook维护的一套框架,并且引用到instagram React只是我们熟悉MVC框中的V层,只是视图层面的一个框架,只有俩个半api(createClass,cr ...

  9. [开发笔记]-未找到与约束ContractName Microsoft.VisualStudio.Text.ITextDocumentFactoryService...匹配的导出【转载自:酷小孩】

    原文地址:http://www.cnblogs.com/babycool/p/3199158.html 今天打算用VisualStudio2012做一个js效果页面测试的时候,打开VS2012新建项目 ...

随机推荐

  1. Sockets使用

    服务端 using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Threading ...

  2. atom插件安装失败解决方法

    在atom 上下载插件失败,可以用下面的方法. 1.找到C:/Users/你的用户名/.atom/packages/文件夹内 2.在.atom packages 目录下 使用gitbash 3.git ...

  3. 特殊场景Sql优化

    一.大表的大数据量修改 问题: 1.大量的行级锁,长时间阻塞   2.主从延时,大批数据不一致 解决方法: 分批次修改 二.大表的表结构修改 问题:长时间锁表 解决方法: 1.从库修改,主从切换,主库 ...

  4. 16.求Sn=a+aa+aaa+aaaa.......之值

    其中a是一个数字,n表示a的位数,例如:2+22+222+2222+22222(此时n=5): #include <stdio.h> #include <stdlib.h> i ...

  5. SpringBoot的学习【1.初学之HelloWorld】

    1.创建Maven项目. 2.引入pom依赖 在springboot官网中找到简单的依赖模板 <parent> <groupId>org.springframework.boo ...

  6. 内存泄露java.lang.OutOfMemoryError: PermGen space解决方法

    PermGen space的全称是Permanent Generation space,是指内存的永久保存区域,这块内存主要是被JVM存放Class和Meta信息的,Class在被Loader时就会被 ...

  7. python int str

    1. int 类型转换 a = "123" b = int(a) b = b+10 print(type(a),a) print(type(b),b) 2. int(num,bas ...

  8. Python学习之路基础篇--01Python的基本常识

    1 计算机基础 首先认识什么是CPU(Central Processing Unit),即中央处理器,相当于人类的大脑.内存,临时储存数据,断电即消失.硬盘,可以长久的储存数据,有固态硬盘,机械硬盘之 ...

  9. AWS Redshift typical error and potential root cause:

    Full join issue: When use full join, the below join condition should not occur: 1, OR statement2, an ...

  10. Unity用GUI绘制Debug/print窗口/控制台-打包后测试

    Unity游戏视窗控制台输出 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享 ...