入门教程:https://www.reactjscn.com/tutorial/tutorial.html

慢慢学习:对照教程文档,逐句猜解,截图

React官网:https://reactjs.org
React中文网站:https://www.reactjscn.com
Github地址:https://github.com/facebook/react
React 技术栈系列教程:http://www.ruanyifeng.com/blog/2016/09/react-technology-stack.html

课前准备

教程简介

效果预览:https://codepen.io/gaearon/pen/gWWZgR?editors=0010

可以点击按钮,按钮格子里出现OX

点击右侧还能返回到某一步骤

前置知识

如果你想重新了解一下 JavaScript 的新特性,我们推荐你阅读 这篇教程:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/A_re-introduction_to_JavaScript

已经读过,懂不懂的不重要,关于类和函数的解释到是很到位

arrow functions:箭头函数:

MDN的JavaScript教程:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Functions/Arrow_functions

ES6教程:http://es6.ruanyifeng.com/#docs/function#箭头函数

classes:类

MDN的JavaScript教程:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Classes

let

const

Babel REPL:https://babeljs.io/repl

“读取-求值-输出”循环(英语:Read-Eval-Print Loop,简称REPL)是一个简单的,交互式的编程环境

Babel 入门教程:http://www.ruanyifeng.com/blog/2016/01/babel.html

如何编写代码

本地搭建React的开发运行环境:现在应该不用,所以略过

总览

React 是什么?

React 是一个采用声明式,高效而且灵活的用来构建用户界面的框架。

React 当中包含了一些不同的组件,我们从使用 React.Component 开始:

逐句猜解

这个class应该是模仿Java来的,extends不就是Java的类继承关键字么
用了ClassName,一般HTML是写class
{}是来写表达式传值的:this指的是这个class类吧
render():渲染函数,,怎么用呢,没说

逐句猜解

一个组件会接受名为props 的参数,并通过名为 render 的方法返回一个嵌套结构的视图。
props:向组件传进去参数用这个
嵌套:说的是一直在调用React.createElement()方法吧

逐句猜解

每一个 React 元素事实上都一个 JavaScript 对象,你可以在你的应用中把它当保存在变量中或者作为参数传递。:这个感觉还容易理解,元素,对象,作为参数

开始编码

模板代码:https://codepen.io/gaearon/pen/oWWQNa?editors=0010

class Square extends React.Component {
  render() {
    return (
      <button className="square">
        {/* TODO */}
      </button>
    );
  }
}

class Board extends React.Component {
  renderSquare(i) {
    return <Square />;
  }

  render() {
    const status = 'Next player: X';

    return (
      <div>
        <div className="status">{status}</div>
        <div className="board-row">
          {this.renderSquare(0)}
          {this.renderSquare(1)}
          {this.renderSquare(2)}
        </div>
        <div className="board-row">
          {this.renderSquare(3)}
          {this.renderSquare(4)}
          {this.renderSquare(5)}
        </div>
        <div className="board-row">
          {this.renderSquare(6)}
          {this.renderSquare(7)}
          {this.renderSquare(8)}
        </div>
      </div>
    );
  }
}

class Game extends React.Component {
  render() {
    return (
      <div className="game">
        <div className="game-board">
          <Board />
        </div>
        <div className="game-info">
          <div>{/* status */}</div>
          <ol>{/* TODO */}</ol>
        </div>
      </div>
    );
  }
}

// ========================================

ReactDOM.render(
  <Game />,
  document.getElementById('root')
);

代码阅读

觉得要从下往上读:最后是在<root>标签下生成<Game />组件,<Game />组件的内容是一堆<div>标签,中括号里传递参数

通过 Props 传递数据

代码阅读

觉得是从父组件传递一个值到子组件:.props意思是所有参数,this.props.value是指组件所有参数中名叫value的参数的值

给组件添加交互功能

查看此步完整代码示例:https://codepen.io/gaearon/pen/VbbVLg?editors=0010

开发工具

浏览器蓝色版(开发版):https://www.mozilla.org/zh-CN/firefox/developer/

源代码界面:https://github.com/facebook/react-devtools

状态提升

查看此步完整代码示例:https://codepen.io/gaearon/pen/ybbQJX?editors=0010

不可变性

函数定义组件

轮流落子

判断赢家

保存历史记录

2019.01.30,看的头晕,下次再看

React 记录(2)的更多相关文章

  1. React 记录(1)

    作为一个前端工程师,前端框架是必须会的,所以开始学习React. 学习的方法是:先实践,后图文记录. React官网:https://reactjs.org React中文网站:https://www ...

  2. React 记录(7)

    React文档:https://www.reactjscn.com/docs/handling-events.html 慢慢学习:对照教程文档,逐句猜解,截图 React官网:https://reac ...

  3. React 记录(6)

    React文档:https://www.reactjscn.com/docs/react-component.html 慢慢学习:对照教程文档,逐句猜解,截图 React官网:https://reac ...

  4. React 记录(5)

    React文档:https://www.reactjscn.com/docs/state-and-lifecycle.html 慢慢学习:对照教程文档,逐句猜解,截图 React官网:https:// ...

  5. React 记录(4)

    React文档:https://www.reactjscn.com/docs/components-and-props.html 慢慢学习:对照教程文档,逐句猜解,截图 React官网:https:/ ...

  6. React 记录(3)

    React文档:https://www.reactjscn.com/docs/hello-world.html 慢慢学习:对照教程文档,逐句猜解,截图 React官网:https://reactjs. ...

  7. react 记录:运行npm run eject命令暴露配置文件都报这个错误

    问题: react 使用create-react-app命令创建一个项目,运行npm run eject命令暴露配置文件都报这个错误 原因:主要是脚手架添加 .gitgnore文件,但是却没有本地仓库 ...

  8. react 记录:React Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history stack

    前言: react-router-dom 4.4.2 在页面中直接使用 import { Link } from 'react-router-dom' //使用 <Link to={{ path ...

  9. Effect Hook

    1 数据获取,设置订阅以及手动更改 React 组件中的 DOM 都属于副作用. 2 可以把 useEffect Hook 看做 componentDidMount,componentDidUpdat ...

随机推荐

  1. ubuntu 16.04 主题美化及终端美化

    如果你使用的是图形界面,你会发现ubuntu默认的界面真是丑的一批,所以简单美化一下: 1.安装unity-tweak-tool: sudo apt-get install unity-tweak-t ...

  2. 【XSY2753】Lcm 分治 FWT FFT 容斥

    题目描述 给你\(n,k\),要你选一些互不相同的正整数,满足这些数的\(lcm\)为\(n\),且这些数的和为\(k\)的倍数. 求选择的方案数.对\(232792561\)取模. \(n\leq ...

  3. python_sort(key=) 的使用

    """ sort() 函数内含有 key 可以指定相关的函数来作为排序依据 比如这里指定每一项的索引为1 的元素作为排序依据 默认是以第一个作为排序依据 "&q ...

  4. wstngfw openVpn站点到站点连接示例(共享密钥)

    wstngfw openVpn站点到站点连接示例(共享密钥) 在本例中,将假设以下设置: 站点 A 站点 B 名称 Beijing Office(北京办公室) 名称 Shenzheng Office( ...

  5. 【题解】 bzoj3555: [Ctsc2014]企鹅QQ (字符串Hash)

    题面戳我 Solution 我们分析题意,他要求的是两个字符串只有一个字符不同,然后我们再看长度\(L \leq 200\),显然我们就可以把每一位删除后\(Hash\),然后判断相同个数即可 我一开 ...

  6. 「ZJOI2015」地震后的幻想乡 解题报告

    「ZJOI2015」地震后的幻想乡 想了半天,打开洛谷题解一看,最高票是_rqy的,一堆密密麻麻的积分差点把我吓跑. 据说有三种解法,然而我只学会了一种最辣鸡的凡人解法. 题意:给一个无向图\(G\) ...

  7. 分离式部署LNMP

    -------Nginx----------PHP+NFS------------MySql------192.168.56.202 192.168.56.201 192.168.56.200安装My ...

  8. [APIO2016]烟火表演

    题目描述 https://www.lydsy.com/JudgeOnline/problem.php?id=4585 题解 这题太神了. 我们可以先列出一个dp方程,dp[x][d]表示x节点到所有叶 ...

  9. 编写高质量代码:改善Java程序的151个建议 --[26~36]

    提防包装类型的null值 public static int testMethod(List<Integer> list) { int count = 0; for (Integer i ...

  10. C++11并发——多线程条件变量std::condition_variable(四)

    https://www.jianshu.com/p/a31d4fb5594f https://blog.csdn.net/y396397735/article/details/81272752 htt ...