react:

component and views : produce html abd add them on a page( in the dom)

<import React from 'react'> // core react library, know how to work with component. Create or manage a Dom
<import ReactDOM from 'react-dom'> //render component to dom const App = function(){
return <div>HI!</div>
}; // this is a component class, could produce a lot of instance.
  • ES6

const: ES6 syntax, declare a variable. And which means it won't change because it is constant
JSX:

  1. subset of javascript which looks like html but cannot be interpreted by browser.
  2. JSX could produce HTML
  3. JSX could be compiled into vanilla javascript( which means plain JS without any additional libraries)
ReactDOM.render(<App />, document.querySelector('.container')); //render component into dom
// transpire would translate JSX into javascript
// <App />is a simple instance of component App
  • functional based component: take in some info and give out some JSX(can contain some class based component)
const App1 = () => {
return (
    <div>
      <SearchBar />
    </div>;
  );
}
// => equals to keyword:this
  • class based component: react user events, keep track of state from render pass to render pass.

每一个class based component 都有一个state object,state is a plain javascript object that used to record and react to user events.

如果state发生了改变,则这个component会将这个改变render到dom中。

我们把不同的component放在不同的文件中,由于文件之间彼此独立,所以我们需要declare the relationships between files.

  • event handeler:每当事件触发时就会被triggered

on+element+event(onChange)

class SearchBar extends React.Component {
constructor(props) {//constructor初始化
super(props);//super调用react.component中的初始化方法
this.state = {term: ''}; //create a new object and pass it to state(只有在)
//functional components dose't have;
}
render() { //render function must return some JSX
return (
<div>
<input onChange={event => this.setState({ term: event.target.value})}/>//event handler, 用this.setState来改变state
Value of the input: {this.state.term}//通过{}来引用值
</div>
);
//event
  • controlled components

state tell the input what it should be

1 render instance of search bar 2 constructor called to new a instance 3 the component renders, the initial value of the input is the is the term.

4 wait for the event, eventhandler changed the state is changed.But the input value hasn't changed. 5 when the render method is used again , then the value has changed by the state.

render() { //render function must return some JSX
return (
<div>
<input
value = {this.state.term} //controlled component value set by state
onChange={event => this.setState({ term: event.target.value})}/>
</div>
);
//eventHandeler would be triggered whenever the event occurs
}
  • downward data flow: most parent component responsible for fetching data

so index.js App should be responsible for fetching data. And all the other

use state to

A Bite Of React(1)的更多相关文章

  1. A Bite Of React(2) Component, Props and State

    component component:用户自己定义的元素 const element = <Welcome name="Sara" />; class Welcome ...

  2. react programming

    So you're curious in learning this new thing called Reactive Programming, particularly its variant c ...

  3. react组件的生命周期

    写在前面: 阅读了多遍文章之后,自己总结了一个.一遍加强记忆,和日后回顾. 一.实例化(初始化) var Button = React.createClass({ getInitialState: f ...

  4. 十分钟介绍mobx与react

    原文地址:https://mobxjs.github.io/mobx/getting-started.html 写在前面:本人英语水平有限,主要是写给自己看的,若有哪位同学看到了有问题的地方,请为我指 ...

  5. RxJS + Redux + React = Amazing!(译一)

    今天,我将Youtube上的<RxJS + Redux + React = Amazing!>翻译(+机译)了下来,以供国内的同学学习,英文听力好的同学可以直接看原版视频: https:/ ...

  6. React 入门教程

    React 起源于Facebook内部项目,是一个用来构建用户界面的 javascript 库,相当于MVC架构中的V层框架,与市面上其他框架不同的是,React 把每一个组件当成了一个状态机,组件内 ...

  7. 通往全栈工程师的捷径 —— react

    腾讯Bugly特约作者: 左明 首先,我们来看看 React 在世界范围的热度趋势,下图是关键词“房价”和 “React” 在 Google Trends 上的搜索量对比,蓝色的是 React,红色的 ...

  8. 2017-1-5 天气雨 React 学习笔记

    官方example 中basic-click-counter <script type="text/babel"> var Counter = React.create ...

  9. RxJS + Redux + React = Amazing!(译二)

    今天,我将Youtube上的<RxJS + Redux + React = Amazing!>的后半部分翻译(+机译)了下来,以供国内的同学学习,英文听力好的同学可以直接看原版视频: ht ...

随机推荐

  1. k8s入门教程

    1. k8s概述 Kubernetes(简称K8S) 是Google开源的分布式的容器管理平台,方便我们在服务器集群中管理我们容器化应用. 教程主要介绍怎么使用阿里云容器服务(kubernetes版本 ...

  2. Java 8实战之读书笔记四:高效Java 8编程

    三.高效Java 8编程 第8章 重构.测试和调试 Java 8的新特性也可以帮助提升代码的可读性:      使用Java 8,你可以减少冗长的代码,让代码更易于理解      通过方法引用和S ...

  3. sig文件制作

    一 配置环境变量 将link.exe,pcf.exe,sigmake.exe添加进PATH环境变量(选择“我的电脑” >“属性”>“高级” >“环境变量”>将文件地址添加进“p ...

  4. C#windows向窗体传递泛型类

    修改窗体代码文件*.cs public partial class FormName<T> : Form partial说明此类还有一半在另外的cs文件中,正是系统替你写好的*.desig ...

  5. Checklist: 2019 05.01 ~ 06.30

    Golang Lessons learned porting 50k loc from Java to Go Five things that make Go fast Simple techniqu ...

  6. 在linux终端中清空文件

    cat /dev/null > file_name vim file_name 把文件的前10行拷贝到新的文件中 head -n10 file_name1 > file_name2

  7. bzoj3812 主旋律 容斥+状压 DP

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=3812 题解 考虑对于图的联通性的 DP 的一般套路:总方案 - 不连通的方案. 那么我们只需要 ...

  8. vue的列表交错过渡

    参考文章 https://juejin.im/post/5cccf5b0e51d453a907b4af1

  9. 使用字符流(Writer、Reader)完成对文件的读写操作

    字符流 字符输出流:Writer,对文件的操作使用子类FileWriter 字符输入流:Reader,对文件的操作使用子类FileReader 每次操作的是一个字符 文件字符操作流会自带缓存,默认大小 ...

  10. 【Shiro】SpringBoot集成Shiro

    项目版本: springboot2.x shiro:1.3.2 Maven配置: <dependency> <groupId>org.apache.shiro</grou ...