SlideShare a Scribd company logo
1 of 20
React 入門
2016/05/30 主講:小賴
介紹
 React 是 Facebook 在 2013 年所發表的一個處理前
端 UI 的開源函式庫。
 Solve one problem:
 Building large applications with data that changes over
time
 解決建置資料不斷更新的大型系統 前端瀏覽效以的問題
 官方網站
特色
 Virtual DOM:讓執行速度加快的關鍵
 Component:提高重用性
Virtual DOM
 由於操作DOM是個昂貴的動作
 React會將頁面結構透過virtual DOM紀錄起來資料變
動時,將virtual DOM與實際的DOM比對只更動需要
異動的部分,以加快呈現速度
元件Component
 定義元件
 ReactClass createClass(object specification)
<div id="example"></div>
<script type="text/babel">
var HelloWorld = React.createClass({
render: function() {
return (
<h1>Hello,World!</h1>
);
}
});
ReactDOM.render(
<HelloWorld/>,
document.getElementById('example')
);
</script>
sample02-component.htm
JSX
JSX是在javascript程式碼當中,看起來類似XML的語法
用來描述頁面結構。
深入JSX
JSX注意事項
 class => className
 for => htmlFor
 JSX 撰寫要符合xml 標準,開放標籤要記得結尾,例如
<br/>
JSX 編譯
 npm install -g react-tools
 jsx --watch src/ build/
 From React 快速導覽
Babel
 The compiler for writing next generation
JavaScript
 <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-
core/5.8.23/browser.min.js"></script>
 Babel REPL
Sample01-helloworld.htm
props
 通常用在靜態資料上
讓父元件傳遞資訊給子元件
sample03-props.htm
state
 存放內部時常變動的資料
sample04-state.htm
refs
sample05-refs.htm
Separate File
<script type="text/babel" src="src/helloworld.js"></script>
Note that some browsers (Chrome, e.g.) will fail to load the file unless
it's served via HTTP.
sample06-separate-file.htm
Component Lifecycle
 Components have three main parts of their lifecycle:
 Mounting: A component is being inserted into the DOM.
 Updating: A component is being re-rendered to determine if the
DOM should be updated.
 Unmounting: A component is being removed from the DOM.
will methods, which are called right before something happens.
did methods which are called right after something happens.
Component Lifecycle
 componentWillMount()
 componentDidMount()
 componentWillReceiveProps(object nextProps)
 shouldComponentUpdate(object nextProps, object nextState)
 componentWillUpdate(object nextProps, object nextState)
 componentDidUpdate(object prevProps, object prevState)
 componentWillUnmount()
佳隆程式改寫(1)
 步驟1,定義Component
 <ChatRoom>
 <MessageBlock>
 <Messages>
 <InputSection>
佳隆程式改寫(2)
 步驟2,資料關聯與事件撰寫
 Props
 State
 Refs
 getInitialState
 onClick、onKeyPress
 靜態資料傳入測試
 sample08-index-chatroom-2.html
佳隆程式改寫(3)
 步驟3,Socket
 動態資料測試
 初始化程式設定 (componentDidMount)
 監聽Socket
sample11-index-chatroom-scoket.html
React Native
 2015 年 3 月份的時候, Facebook 開放了 React
Native 的原始碼
 利用 JavaScript 建立原生 iOS 及 Android App 的框架
 「只需撰寫一次,到處皆可執行」( Write Once,
Run Everywhere )
其它參考連結
 [ReactJs]第一個實戰範例
 React Native (Teyou)
 不要只因為性能考量而選擇 React.js
 React基礎教學
 React Native 簡介:以 JavaScript 建構 iOS App
 ReactJS and Socket.IO Chat Application
 Windows下搭建React Native Android開發環境詳解
 React Native官網

More Related Content

What's hot

HTML5 規格最新發展現況 (HTML5 趨勢發展與技術應用論壇)
HTML5 規格最新發展現況 (HTML5 趨勢發展與技術應用論壇)HTML5 規格最新發展現況 (HTML5 趨勢發展與技術應用論壇)
HTML5 規格最新發展現況 (HTML5 趨勢發展與技術應用論壇)Will Huang
 
SignalR實戰技巧 twmvc#17
SignalR實戰技巧 twmvc#17 SignalR實戰技巧 twmvc#17
SignalR實戰技巧 twmvc#17 twMVC
 
AngularJS training in Luster
AngularJS training in LusterAngularJS training in Luster
AngularJS training in LusterJason Chung
 
Angular 4 網站開發最佳實務 (Modern Web 2017)
Angular 4 網站開發最佳實務 (Modern Web 2017)Angular 4 網站開發最佳實務 (Modern Web 2017)
Angular 4 網站開發最佳實務 (Modern Web 2017)Will Huang
 
React.js what do you really mean?
React.js what do you really mean?React.js what do you really mean?
React.js what do you really mean?昱安 周
 
簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率
簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率
簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率Shengyou Fan
 
SITCON 2016 ─ Modern Front-End Workflow with Webpack
SITCON 2016 ─ Modern Front-End Workflow with WebpackSITCON 2016 ─ Modern Front-End Workflow with Webpack
SITCON 2016 ─ Modern Front-End Workflow with Webpack昱安 周
 
ModernWeb 2017 angular component
ModernWeb 2017 angular componentModernWeb 2017 angular component
ModernWeb 2017 angular componentChieh Kai Yang
 
百度前端性能监控与优化实践
百度前端性能监控与优化实践百度前端性能监控与优化实践
百度前端性能监控与优化实践Welefen Lee
 
用Maven管理專案的依賴關係
用Maven管理專案的依賴關係用Maven管理專案的依賴關係
用Maven管理專案的依賴關係Huang Bruce
 
Angular js twmvc#17
Angular js twmvc#17Angular js twmvc#17
Angular js twmvc#17twMVC
 
Dynamic JS Loader
Dynamic JS LoaderDynamic JS Loader
Dynamic JS Loaderfeifeipan
 
Subversion快速入门教程
Subversion快速入门教程Subversion快速入门教程
Subversion快速入门教程wensheng wei
 
Angular.js & ASP.NET in Study4
Angular.js & ASP.NET in Study4Angular.js & ASP.NET in Study4
Angular.js & ASP.NET in Study4Kyle Shen
 
前端爆肝之旅+React上山前的小專案心得分享
前端爆肝之旅+React上山前的小專案心得分享前端爆肝之旅+React上山前的小專案心得分享
前端爆肝之旅+React上山前的小專案心得分享Yao Nien Chung
 
打造輕量化手機網站
打造輕量化手機網站打造輕量化手機網站
打造輕量化手機網站Rei Ayanami
 
前端编译平台
前端编译平台前端编译平台
前端编译平台Welefen Lee
 
Build your ETL job using Jenkins - step by step
Build your ETL job using Jenkins - step by stepBuild your ETL job using Jenkins - step by step
Build your ETL job using Jenkins - step by stepBryan Yang
 
全新 Windows Server 2019 容器技術 及邁向與 Kubernetes 整合之路 (Windows Server 高峰會)
全新 Windows Server 2019 容器技術及邁向與 Kubernetes 整合之路 (Windows Server 高峰會)全新 Windows Server 2019 容器技術及邁向與 Kubernetes 整合之路 (Windows Server 高峰會)
全新 Windows Server 2019 容器技術 及邁向與 Kubernetes 整合之路 (Windows Server 高峰會)Will Huang
 

What's hot (20)

HTML5 規格最新發展現況 (HTML5 趨勢發展與技術應用論壇)
HTML5 規格最新發展現況 (HTML5 趨勢發展與技術應用論壇)HTML5 規格最新發展現況 (HTML5 趨勢發展與技術應用論壇)
HTML5 規格最新發展現況 (HTML5 趨勢發展與技術應用論壇)
 
SignalR實戰技巧 twmvc#17
SignalR實戰技巧 twmvc#17 SignalR實戰技巧 twmvc#17
SignalR實戰技巧 twmvc#17
 
AngularJS training in Luster
AngularJS training in LusterAngularJS training in Luster
AngularJS training in Luster
 
Angular 4 網站開發最佳實務 (Modern Web 2017)
Angular 4 網站開發最佳實務 (Modern Web 2017)Angular 4 網站開發最佳實務 (Modern Web 2017)
Angular 4 網站開發最佳實務 (Modern Web 2017)
 
React.js what do you really mean?
React.js what do you really mean?React.js what do you really mean?
React.js what do you really mean?
 
簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率
簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率
簡化 JVM 上雲 - 透過 Azure Spring Cloud 提升開發、發佈及服務監控效率
 
SITCON 2016 ─ Modern Front-End Workflow with Webpack
SITCON 2016 ─ Modern Front-End Workflow with WebpackSITCON 2016 ─ Modern Front-End Workflow with Webpack
SITCON 2016 ─ Modern Front-End Workflow with Webpack
 
ModernWeb 2017 angular component
ModernWeb 2017 angular componentModernWeb 2017 angular component
ModernWeb 2017 angular component
 
百度前端性能监控与优化实践
百度前端性能监控与优化实践百度前端性能监控与优化实践
百度前端性能监控与优化实践
 
用Maven管理專案的依賴關係
用Maven管理專案的依賴關係用Maven管理專案的依賴關係
用Maven管理專案的依賴關係
 
Angular js twmvc#17
Angular js twmvc#17Angular js twmvc#17
Angular js twmvc#17
 
Dynamic JS Loader
Dynamic JS LoaderDynamic JS Loader
Dynamic JS Loader
 
Subversion快速入门教程
Subversion快速入门教程Subversion快速入门教程
Subversion快速入门教程
 
Angular.js & ASP.NET in Study4
Angular.js & ASP.NET in Study4Angular.js & ASP.NET in Study4
Angular.js & ASP.NET in Study4
 
前端爆肝之旅+React上山前的小專案心得分享
前端爆肝之旅+React上山前的小專案心得分享前端爆肝之旅+React上山前的小專案心得分享
前端爆肝之旅+React上山前的小專案心得分享
 
打造輕量化手機網站
打造輕量化手機網站打造輕量化手機網站
打造輕量化手機網站
 
前端编译平台
前端编译平台前端编译平台
前端编译平台
 
Build your ETL job using Jenkins - step by step
Build your ETL job using Jenkins - step by stepBuild your ETL job using Jenkins - step by step
Build your ETL job using Jenkins - step by step
 
全新 Windows Server 2019 容器技術 及邁向與 Kubernetes 整合之路 (Windows Server 高峰會)
全新 Windows Server 2019 容器技術及邁向與 Kubernetes 整合之路 (Windows Server 高峰會)全新 Windows Server 2019 容器技術及邁向與 Kubernetes 整合之路 (Windows Server 高峰會)
全新 Windows Server 2019 容器技術 及邁向與 Kubernetes 整合之路 (Windows Server 高峰會)
 
How tovuejs
How tovuejsHow tovuejs
How tovuejs
 

Similar to React js入門

react native by letv
react native by letvreact native by letv
react native by letvfeeloc
 
MobileWebAppFramework_V5_design
MobileWebAppFramework_V5_designMobileWebAppFramework_V5_design
MobileWebAppFramework_V5_designJackson Tian
 
Hello reactJS 0~1 Bulid my first web app
Hello reactJS 0~1 Bulid my first web appHello reactJS 0~1 Bulid my first web app
Hello reactJS 0~1 Bulid my first web apphungjie19
 
Ajax应用开发最佳实践
Ajax应用开发最佳实践Ajax应用开发最佳实践
Ajax应用开发最佳实践Fu Cheng
 
React单页应用性能调优实践
React单页应用性能调优实践React单页应用性能调优实践
React单页应用性能调优实践spray_lx
 
Thinking in React by Deot
Thinking in React by Deot Thinking in React by Deot
Thinking in React by Deot 荣德 周
 
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天Gelis Wu
 
D2-ETao-show
D2-ETao-showD2-ETao-show
D2-ETao-showleneli
 
Learning JavaScript in Three Web Apps(中文)
Learning JavaScript in Three Web Apps(中文)Learning JavaScript in Three Web Apps(中文)
Learning JavaScript in Three Web Apps(中文)Dexter Yang
 
【项目分享】赶集移动Web App开发总结
【项目分享】赶集移动Web App开发总结 【项目分享】赶集移动Web App开发总结
【项目分享】赶集移动Web App开发总结 yangdj
 
ASP.NET Core 2.1設計新思維與新發展
ASP.NET  Core 2.1設計新思維與新發展ASP.NET  Core 2.1設計新思維與新發展
ASP.NET Core 2.1設計新思維與新發展江華 奚
 
移动Web开发框架jqm探讨
移动Web开发框架jqm探讨移动Web开发框架jqm探讨
移动Web开发框架jqm探讨newker
 
Real World ASP.NET MVC
Real World ASP.NET MVCReal World ASP.NET MVC
Real World ASP.NET MVCjeffz
 
Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有Wade Huang
 
Struts+Spring+Hibernate整合教程
Struts+Spring+Hibernate整合教程Struts+Spring+Hibernate整合教程
Struts+Spring+Hibernate整合教程yiditushe
 
Struts+Spring+Hibernate整合教程
Struts+Spring+Hibernate整合教程Struts+Spring+Hibernate整合教程
Struts+Spring+Hibernate整合教程appollo0312
 
赶集团购开发总结4
赶集团购开发总结4赶集团购开发总结4
赶集团购开发总结4yangdj
 
JSDC 2015 React-Native 實戰
JSDC 2015 React-Native 實戰JSDC 2015 React-Native 實戰
JSDC 2015 React-Native 實戰Sam Lee
 

Similar to React js入門 (20)

react native by letv
react native by letvreact native by letv
react native by letv
 
MobileWebAppFramework_V5_design
MobileWebAppFramework_V5_designMobileWebAppFramework_V5_design
MobileWebAppFramework_V5_design
 
Hello reactJS 0~1 Bulid my first web app
Hello reactJS 0~1 Bulid my first web appHello reactJS 0~1 Bulid my first web app
Hello reactJS 0~1 Bulid my first web app
 
Ajax应用开发最佳实践
Ajax应用开发最佳实践Ajax应用开发最佳实践
Ajax应用开发最佳实践
 
React单页应用性能调优实践
React单页应用性能调优实践React单页应用性能调优实践
React单页应用性能调优实践
 
Thinking in React by Deot
Thinking in React by Deot Thinking in React by Deot
Thinking in React by Deot
 
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
 
J S教材
J S教材J S教材
J S教材
 
D2-ETao-show
D2-ETao-showD2-ETao-show
D2-ETao-show
 
Learning JavaScript in Three Web Apps(中文)
Learning JavaScript in Three Web Apps(中文)Learning JavaScript in Three Web Apps(中文)
Learning JavaScript in Three Web Apps(中文)
 
【项目分享】赶集移动Web App开发总结
【项目分享】赶集移动Web App开发总结 【项目分享】赶集移动Web App开发总结
【项目分享】赶集移动Web App开发总结
 
ASP.NET Core 2.1設計新思維與新發展
ASP.NET  Core 2.1設計新思維與新發展ASP.NET  Core 2.1設計新思維與新發展
ASP.NET Core 2.1設計新思維與新發展
 
Vue.js
Vue.jsVue.js
Vue.js
 
移动Web开发框架jqm探讨
移动Web开发框架jqm探讨移动Web开发框架jqm探讨
移动Web开发框架jqm探讨
 
Real World ASP.NET MVC
Real World ASP.NET MVCReal World ASP.NET MVC
Real World ASP.NET MVC
 
Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有
 
Struts+Spring+Hibernate整合教程
Struts+Spring+Hibernate整合教程Struts+Spring+Hibernate整合教程
Struts+Spring+Hibernate整合教程
 
Struts+Spring+Hibernate整合教程
Struts+Spring+Hibernate整合教程Struts+Spring+Hibernate整合教程
Struts+Spring+Hibernate整合教程
 
赶集团购开发总结4
赶集团购开发总结4赶集团购开发总结4
赶集团购开发总结4
 
JSDC 2015 React-Native 實戰
JSDC 2015 React-Native 實戰JSDC 2015 React-Native 實戰
JSDC 2015 React-Native 實戰
 

React js入門

Editor's Notes

  1. http://facebook.github.io/react/jsx-compiler.html
  2. Mounting: A component is being inserted into the DOM. Updating: A component is being re-rendered to determine if the DOM should be updated. Unmounting: A component is being removed from the DOM.