SlideShare a Scribd company logo
1 of 23
ShoppingCart
React - state
By ReactMaker - Andy
關於我們
成員介紹
Andy
一頭栽進前端世界的小小工程師,喜歡
玩各種前端新鮮事物。 目前專注於
ReactJS,使用過Flux、Redux、Mobx
等單向資料流進行專案開發。
Giant
在團隊中擔任聯絡窗口,目前是高應大
碩生,由於對前端開發有興趣,因此就
跟大大們一起組成讀書會,專注於學習
ReactJs。
Hyman
前端工程師,喜歡研究新的技術,也喜
歡研究有趣的UI跟效果,想要帶領更多
的人進入ReactJS的世界,最近在研究
Mobx.js!
前情提要
https://github.com/ReactMaker/reactstrap_example
這次我們要做的是
https://github.com/ReactMaker/shopping_cart_demo
What is state?
狀態是Component的內部物件
儲存了可變動的資料
讓Component自己管理DOM元件的生成及變動
Data render
jQuery
需要的值從DOM抓取
並直接修改DOM
$(selector).text(“text1”)
資料導向,以state產生畫面
無直接對DOM進行操作
<span>{this.state.text}</span>React
海門 Hyman
用愛心來做事,用感恩的心做人
迪倫 Andy
人永遠在追求快活,永遠在逃避痛苦
及米 Jimmy
信念、毅力、勇氣三者具備
小森 Winsome
互相瞭解是朋友,互相理解是知己
x
{
name: '海門 Hyman',
desc: '用愛心來做事,用感恩的心做人'
}
海綿 Hyman
用愛心來做事,用感恩的心做人
{
name: '海綿 Hyman',
desc: '用愛心來做事,用感恩的心做人'
}
React Render
Render 畫面
state
{count: 1}
render
1
setState
{count: 2}
1
2
3
2
簡單做個state示範吧
DEMO
來把它弄活吧
Step 1
取得API Data
https://goo.gl/jNEnKV
Step 2
建立cart state
顯示購物車物品數量
https://goo.gl/MDbA1i
Step 3
新增addToCart function
https://goo.gl/UGRbQt
Step 4
購買按鈕綁定addToCart function
https://goo.gl/63kckr
Step 5
購買後disabled
https://goo.gl/d2Zm5T
Step 6
購物車呈現購買物品
https://goo.gl/61aAZw
Step 7
計算總金額
https://goo.gl/tbVyba
Step 8
購物車加入刪除按鈕
https://goo.gl/dZHGrr
Step 9
購物車無商品時
不能點擊結帳按鈕
https://goo.gl/BC1Vpg
Step 10
點擊結帳按鈕
顯示總金額
https://goo.gl/MjsvdZ
What is props?
props是唯讀的且單向的
由父component傳給子component
<User name={this.state.name} />
props
props props
props
切Component
carts
deleteCartItem
products
addToCart
別忘了追蹤我們

More Related Content

Similar to ReactMaker - state 製作購物車範例

React js入門
React js入門React js入門
React js入門昶宇 賴
 
React Native on Android
React Native on AndroidReact Native on Android
React Native on Android萬皇 楊
 
react native by letv
react native by letvreact native by letv
react native by letvfeeloc
 
常用Js框架比较
常用Js框架比较常用Js框架比较
常用Js框架比较Adam Lu
 
React Native + Redux
React Native + ReduxReact Native + Redux
React Native + ReduxCh Rick
 
20141212 html5 及微軟跨平台佈局 long
20141212 html5 及微軟跨平台佈局   long20141212 html5 及微軟跨平台佈局   long
20141212 html5 及微軟跨平台佈局 longMeng-Ru (Raymond) Tsai
 
React基礎教學
React基礎教學React基礎教學
React基礎教學昇倫 蔡
 
Thinking in React by Deot
Thinking in React by Deot Thinking in React by Deot
Thinking in React by Deot 荣德 周
 
《Linux运维趋势》2012年5月号 总第19期
《Linux运维趋势》2012年5月号 总第19期《Linux运维趋势》2012年5月号 总第19期
《Linux运维趋势》2012年5月号 总第19期51CTO
 
【1110ROS社群開講】實務經驗分享,初階也能快速上手!_林威志
【1110ROS社群開講】實務經驗分享,初階也能快速上手!_林威志【1110ROS社群開講】實務經驗分享,初階也能快速上手!_林威志
【1110ROS社群開講】實務經驗分享,初階也能快速上手!_林威志MAKERPRO.cc
 
React-Native share
React-Native shareReact-Native share
React-Native shareEddie Hsu
 
前端工程開發實務訓練
前端工程開發實務訓練前端工程開發實務訓練
前端工程開發實務訓練Joseph Chiang
 
JSDC 2019 給我一個放棄 React 的理由
JSDC 2019 給我一個放棄 React 的理由JSDC 2019 給我一個放棄 React 的理由
JSDC 2019 給我一個放棄 React 的理由Sam Lee
 
程序组介绍Ver2.0
程序组介绍Ver2.0程序组介绍Ver2.0
程序组介绍Ver2.0vtmers2012
 
Insider Dev Tour - Taipei Productive and Fun Web Development with NodeJS and ...
Insider Dev Tour - Taipei Productive and Fun Web Development with NodeJS and ...Insider Dev Tour - Taipei Productive and Fun Web Development with NodeJS and ...
Insider Dev Tour - Taipei Productive and Fun Web Development with NodeJS and ...jasonzheng50
 
Csdn Java电子杂志第1期
Csdn Java电子杂志第1期Csdn Java电子杂志第1期
Csdn Java电子杂志第1期yiditushe
 
Java Web框架汇总
Java Web框架汇总Java Web框架汇总
Java Web框架汇总yiditushe
 
Web爬虫那点事
Web爬虫那点事Web爬虫那点事
Web爬虫那点事Yihua Huang
 
A dev ops team's practice in trend micro in agile summit 2018
A dev ops team's practice in trend micro in agile summit 2018A dev ops team's practice in trend micro in agile summit 2018
A dev ops team's practice in trend micro in agile summit 2018Juggernaut Liu
 

Similar to ReactMaker - state 製作購物車範例 (20)

React js入門
React js入門React js入門
React js入門
 
React Native on Android
React Native on AndroidReact Native on Android
React Native on Android
 
react native by letv
react native by letvreact native by letv
react native by letv
 
常用Js框架比较
常用Js框架比较常用Js框架比较
常用Js框架比较
 
React Native + Redux
React Native + ReduxReact Native + Redux
React Native + Redux
 
20141212 html5 及微軟跨平台佈局 long
20141212 html5 及微軟跨平台佈局   long20141212 html5 及微軟跨平台佈局   long
20141212 html5 及微軟跨平台佈局 long
 
React基礎教學
React基礎教學React基礎教學
React基礎教學
 
Thinking in React by Deot
Thinking in React by Deot Thinking in React by Deot
Thinking in React by Deot
 
《Linux运维趋势》2012年5月号 总第19期
《Linux运维趋势》2012年5月号 总第19期《Linux运维趋势》2012年5月号 总第19期
《Linux运维趋势》2012年5月号 总第19期
 
【1110ROS社群開講】實務經驗分享,初階也能快速上手!_林威志
【1110ROS社群開講】實務經驗分享,初階也能快速上手!_林威志【1110ROS社群開講】實務經驗分享,初階也能快速上手!_林威志
【1110ROS社群開講】實務經驗分享,初階也能快速上手!_林威志
 
React-Native share
React-Native shareReact-Native share
React-Native share
 
前端工程開發實務訓練
前端工程開發實務訓練前端工程開發實務訓練
前端工程開發實務訓練
 
JSDC 2019 給我一個放棄 React 的理由
JSDC 2019 給我一個放棄 React 的理由JSDC 2019 給我一個放棄 React 的理由
JSDC 2019 給我一個放棄 React 的理由
 
程序组介绍Ver2.0
程序组介绍Ver2.0程序组介绍Ver2.0
程序组介绍Ver2.0
 
Insider Dev Tour - Taipei Productive and Fun Web Development with NodeJS and ...
Insider Dev Tour - Taipei Productive and Fun Web Development with NodeJS and ...Insider Dev Tour - Taipei Productive and Fun Web Development with NodeJS and ...
Insider Dev Tour - Taipei Productive and Fun Web Development with NodeJS and ...
 
Csdn Java电子杂志第1期
Csdn Java电子杂志第1期Csdn Java电子杂志第1期
Csdn Java电子杂志第1期
 
Java Web框架汇总
Java Web框架汇总Java Web框架汇总
Java Web框架汇总
 
Web爬虫那点事
Web爬虫那点事Web爬虫那点事
Web爬虫那点事
 
A dev ops team's practice in trend micro in agile summit 2018
A dev ops team's practice in trend micro in agile summit 2018A dev ops team's practice in trend micro in agile summit 2018
A dev ops team's practice in trend micro in agile summit 2018
 
行動技術開發概論
行動技術開發概論行動技術開發概論
行動技術開發概論
 

ReactMaker - state 製作購物車範例