Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
React & Component
Search
ningzbruc
January 01, 2016
Programming
47
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
React & Component
React 简介与升级
ningzbruc
January 01, 2016
More Decks by ningzbruc
See All by ningzbruc
如何写出一个优秀的开源库
ningzbruc
0
68
去啊无线前端的一天
ningzbruc
1
200
阿里旅行去啊H5首页总结&Promise
ningzbruc
0
270
KISSY.Base - all about that Base
ningzbruc
0
140
Hammer.js
ningzbruc
1
340
淘宝旅行门票iPad版开发
ningzbruc
0
140
Travel on KISSY mini
ningzbruc
0
210
Events
ningzbruc
2
130
Why YUI3
ningzbruc
0
190
Other Decks in Programming
See All in Programming
kubernetes コンポーネント開発入門 / 新卒N年目の勉強会&交流会!〜〇〇への誘い〜 #n_study
mazrean
0
240
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
170
Family mrubyの進捗
kishima
1
120
20260828_品質と開発生産性を両立させる、AI時代のE2Eテストの考え方
magicpod
0
210
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
310
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
550
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
190
VueプロジェクトをTypeScript7に対応させる- Side-by-Side戦略による一部高速化 -
koukimiura
0
110
AIを上手に使っていこうとしたら越境せざるを得なくなった話 〜実践1年で見えた境界を越えなければならない理由と進め方〜 / Crossing borders with AI
tomoyakitaura
4
1.1k
AI に Inclusive UI を書かせよう — Design Rules Skill で Compose UI を作り直す
theoriatec2024
1
490
一参加者から『中の人』へ 〜全通PHPerがブースに立って学んだ、カンファレンスを100倍楽しむコツ〜
wp_daisuke
0
150
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
450
Featured
See All Featured
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
200
Side Projects
sachag
456
43k
30 Presentation Tips
portentint
PRO
1
390
It's Worth the Effort
3n
188
29k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
450
Skip the Path - Find Your Career Trail
mkilby
1
230
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
450
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
510
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.9k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
330
Transcript
React & Component ᡡᇌ
React فᳪکන A Facebook & Instagram collaboration.
# React
React • Web Component • Just View • Finite State
Machine • Virtual DOM
Web Component <input type="checkbox" value="yes" checked="checked" /> <select> <option value="1">1</option>
<option value="2" selected="selected">2</option> </select> new ScrollList({ container: '.scroll-list', data: [] }).render(); <SearchSuggest value="۹Ղ" source={this.source} /> <ScrollList data={this.data} /> DOM: React: Component:
Just View render() { return ( <div> <SearchSuggest source={this.source} />
<ScrollList data={this.data} /> </div> ); } return (SingleComponent || Array)
Finite State Machine render() { return ( <div> <SearchSuggest source={this.source}
/> {this.state.showList ? ( <ScrollList data={this.data} /> ) : null} </div> ); }
Virtual DOM render() { return ( <div> <SearchSuggest source={this.source} />
{this.state.showList ? ( <ScrollList data={this.data} /> ) : null} </div> ); } this.setState({ showList: true });
Props & State defaultProps = { width: 100, height: 200
}; constructor() { super(); this.state = { visible: true }; } <Overlay width={300} height={300} onClose={this.onClose} /> render() { return ( {this.state.visible ? ( <div style={{ width: this.props.width, height: this.props.height }}></div> ) : null} ); } close() { this.setState({ visible: false }); this.props.onClose(); }
vs. Kissy ATTRS ATTRS = { width: { value: 100
}, height: { value: 200 }, visible: { value: true } }; this.set('width', 300); this.set('visible', false); 配置参数与ᕟ件状ா混淆 this.after('visibleChange', function(e) { e.newValue ? this.show() : this.hide(); }); 手动管理ى联状ா与UI
DOM Props render() { return ( {this.state.visible ? ( <div
ref="container" className="container" style={{ width: this.props.width, height: this.props.height }} > </div> ) : null} ); } this.refs.container.addEventListener('click', () => {}, false);
ClassName className="container" import styles from “./index.scss"; className={styles.container} import ClassNames from
"classnames/bind"; let cx = ClassNames.bind(styles); className={cx({ container: true, hidden: !this.state.visible })} import CSSModules from 'react-css-modules'; @CSSModules(styles); styleName="container" // class="container" // class="overlay__container___1K9zE" // class="overlay__container___1K9zE overlay__hidden___1K8jY" // class="overlay__container___1K9zE"
Event System render() { return ( <div ref="container" className="container" onClick={this.onClick.bind(this)}
onTouchTap={this.onTap.bind(this)} > </div> ); }
SyntheticEvent console.log({...e}); e.nativeEvent.preventDefault();
LifeCycle: React vs. Kissy class Overlay extends React.Component { static
propTypes = { width: React.PropTypes.number }; static defaultProps = { width: 200 }; constructor() { super(); this.state = { visible: true }; }; componentWillMount() {}, render(), componentDidMount(), componentWillUpdate(), componentDidUpdate(), componentWillUnmount(), }; Base.extend({ initializer() {}, renderUI() {}, bindUI() {}, syncUI(){}, destroy() {} }, { ATTRS: { width: { value: 200, validator: S.isNumber } } });
componentWillReceiveProps defaultProps = { visible: false }; constructor() { super();
this.state = { visible: this.props.visible }; } componentWillReceiveProps(nextProps) { if (this.props.visible !== nextProps.visible) { this.setState({ visible: nextProps.visible }); } } render() { return ( {this.state.visible ? ( <div style={this.props.style}></div> ) : null} ); } render() { return ( <Overlay visible={this.state.active} /> ); } 子ᕟ件 父ᕟ件
Pass Props render() { return ( <form> <input type="input" {...this.props}
/> <button>ݐၾ</button> </form> ); } let { onValueChange, ...inputProps } = this.props; render() { return ( <form> <input type="input" {...inputProps} /> <button>ݐၾ</button> </form> ); } <SearchInput placeholder=“ᔱ" value="۹Ղ" onValueChange={this.change} />
Child Event render() { return ( <form> <input ref="input" type=“input"
value={this.state.value} {...this.props} onInput={() => this.setState({ value: this.refs.input.value })} /> {this.state.value ? (<button>x</button>) : null } </form> ); }
Children render() { return ( {this.state.visible ? ( <div>{this.props.children}</div> )
: null} ); } <Overlay visible="true"> <p>౯ฎٖ౯ฎٖ</p> <p>౯ฎٖ౯ฎٖ</p> <p>౯ฎٖ౯ฎٖ</p> </Overlay> React.Children.map(this.props.children, fn); React.Children.forEach(this.props.children, fn);
Performance render() { return ( {this.state.visible ? ( <div>{this.props.children}</div> )
: null} ); } render() { return ( <div className={this.state.visible : '' : 'hidden'}> {this.props.children} </div> ); } 避免过多生成ᲀ毁 优先样式展示ᵌ藏
key render() { return ( <ul> {this.props.items.map((item, index) => {
return (<li key={'item_' + index}>{item.name}</li>) })} </ul> ); } 方便DOMᜓ点重复利用
shouldComponentUpdate shouldComponentUpdate(nextProps, nextState) { if (this.state.visible !== nextState.visible) { return
true; } return false; } 必要的时候才更新UI 但state多的时候不好管理
None
None
# ReactNative
learn once, write everywhere!
Native vs. Web • View -> div • Text ->
span • Image -> img, background-image • TextInput -> input • TouchableHighlight -> div.onclick • AsyncStorage -> localStorage • …
None
Styles
getStyles
!zIndex https://www.npmjs.com/package/react-native-order-children
# React <=> RN EZ…
# ?PI
None
Join us!!!
THE END.