A Bite Of React(1)
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:
- subset of javascript which looks like html but cannot be interpreted by browser.
- JSX could produce HTML
- 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)的更多相关文章
- A Bite Of React(2) Component, Props and State
component component:用户自己定义的元素 const element = <Welcome name="Sara" />; class Welcome ...
- react programming
So you're curious in learning this new thing called Reactive Programming, particularly its variant c ...
- react组件的生命周期
写在前面: 阅读了多遍文章之后,自己总结了一个.一遍加强记忆,和日后回顾. 一.实例化(初始化) var Button = React.createClass({ getInitialState: f ...
- 十分钟介绍mobx与react
原文地址:https://mobxjs.github.io/mobx/getting-started.html 写在前面:本人英语水平有限,主要是写给自己看的,若有哪位同学看到了有问题的地方,请为我指 ...
- RxJS + Redux + React = Amazing!(译一)
今天,我将Youtube上的<RxJS + Redux + React = Amazing!>翻译(+机译)了下来,以供国内的同学学习,英文听力好的同学可以直接看原版视频: https:/ ...
- React 入门教程
React 起源于Facebook内部项目,是一个用来构建用户界面的 javascript 库,相当于MVC架构中的V层框架,与市面上其他框架不同的是,React 把每一个组件当成了一个状态机,组件内 ...
- 通往全栈工程师的捷径 —— react
腾讯Bugly特约作者: 左明 首先,我们来看看 React 在世界范围的热度趋势,下图是关键词“房价”和 “React” 在 Google Trends 上的搜索量对比,蓝色的是 React,红色的 ...
- 2017-1-5 天气雨 React 学习笔记
官方example 中basic-click-counter <script type="text/babel"> var Counter = React.create ...
- RxJS + Redux + React = Amazing!(译二)
今天,我将Youtube上的<RxJS + Redux + React = Amazing!>的后半部分翻译(+机译)了下来,以供国内的同学学习,英文听力好的同学可以直接看原版视频: ht ...
随机推荐
- topic模式下的收发
生产者: import pika import sys connection = pika.BlockingConnection(pika.ConnectionParameters( host='lo ...
- ActiveMQ的简单使用
项目中使用的介绍 一.运行ActiveMQ 在文件路径下...\apache-activemq-5.13.3\bin\win64 运行activemq.bat 这是系统中的使用,运行后还可以访问相应的 ...
- 如何处理HTML5新标签的浏览器兼容性问题?
① IE8/IE7/IE6支持通过document.createElement方法产生的标签,可以利用这一特性让这些浏览器支持HTML5新标签 ② 也可以使用成熟的框架 ex:html5shim &l ...
- C# DataTable、实体相互转换
public static T GetEntity<T>(DataTable table) where T : new() { T entity = new T(); foreach (D ...
- 转载一篇别人分享的VSFTPD.CONF的中文解释方便以后查询
# 服务器以standalong模式运行,这样可以进行下面的控制 listen=YES # 接受匿名用户 anonymous_enable=YES # 匿名用户login时不询问口令 no_anon_ ...
- 解决Layui数据表格中checkbox位置不居中
1.情景 使用方法渲染的方式生成数据表格,添加了checkbox,但发现checkbox位置不居中,如下图所示 2.解决办法 通过layui官方社区,找到如下代码,只需要添加如下样式即可解决 < ...
- 【记录】spring/springboot 配置mybatis打印sql
======================springboot mybatis 打印sql========================================== 方式 一: ##### ...
- spring-boot-shiro-jwt-redis实现登陆授权功能
一.前言 在微服务中我们一般采用的是无状态登录,而传统的session方式,在前后端分离的微服务架构下,如继续使用则必将要解决跨域sessionId问题.集群session共享问题等等.这显然是费力不 ...
- 使用stylelint进行Vue项目样式检查
stylelint是一个强大的现代 CSS 检测器,可以让开发者在样式表中遵循一致的约定和避免错误.拥有超过170条的规则,包括捕捉错误.最佳实践.控制可以使用的语言特性和强制代码风格规范.它支持最新 ...
- 【leetcode】1014. Capacity To Ship Packages Within D Days
题目如下: A conveyor belt has packages that must be shipped from one port to another within D days. The ...