react - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · facebook...

26
React ޗڡ[email protected]

Upload: others

Post on 30-May-2020

23 views

Category:

Documents


0 download

TRANSCRIPT

Page 2: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

Who are React?

• Facebook

•• 2015.15.20

• React-Native, React-Canvas

Page 3: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

Why React?

• web component

• UI DOM

Page 4: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

Why React?

• JSX

•• Virtual DOM

• React Native App

Page 5: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

How to use?

• react.js: React

• rect-dom.js: DOM

• browser.js: JSX javascript

• <script> type=“text/babel”

Page 6: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

How to use?• ReactDOM.render()

Page 7: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

JSX

• javascript XML

• HTML

• XSS(dangerouslySetInnerHTML)

• HTML ’data-’

• className, htmlFor, style(object)

Page 8: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

JSX

• ‘{}’ js

• arr.map(function() {})

Page 9: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

• React

•onClick Capture

• e.stopPropagation() e.preventDefault()

Page 10: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

• value input/textarea

input value

defaultValue

onChange

textarea value

selectoption selected

radiocheckbox

checked defaultChecked

Page 11: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

• render

Page 12: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

-

• this.props: ( )

• getDefaultProps:

• this.props.children:

• array | object | string | undefined

• React.Children

Page 13: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

-

• propTypes:

• react

• function(props, propName, componentName)

Page 14: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

-

• propTypes:

• react

• function(props, propName, componentName)

Page 15: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

-

• this.state:

• getInitialState:

• this.setState: ( )

Page 16: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

- Mountingrender()

Updatingrender()

Unmounting

componentWillMount()

componentWillUpdate()

getDefaultProps()

getInitialState()

componentWillUnmount()

shouldComponentUpdate()

componentD

idUpdate()

ReactDOM.unmountCompone

ntAtNode

componentDidMount()

com

pone

ntW

illRe

ceive

Prop

s()

trueState

props

Page 17: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

-

Page 18: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

-

Page 19: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

- DOM• this.refs[refName]

DOM

• ref

• ReactDOM.findDOMNode(this)

Page 20: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

- mixins• Array of Object:

• mixins

• mixin

Page 21: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

-

• props

• Pub/Sub

• flux

Page 22: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

flux -

• Action: Action

• Dispatcher: Store, Store

• Store: Action View

• View: Store Action(react components)

• Facebook Flux, Redux, Reflux

Page 23: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

- react-with-addons

Page 24: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ

• sublime Text JSX

• : babel-sublime

• JSX Emmet

• React

• webpack

• Chrome Extension: React Developer Tools

Page 26: React - xgfexgfe.github.io/uploads/felix/react/react-first-kiss.pdf · 2020-02-20 · Facebook Flux, Redux, Reflux. J o - react-with-addons ... • React d ± Æ § • webpack ñ