004. working with react component

12
004. WORKING WITH REACT COMPONENT Presenter: Binh Quan

Upload: binh-quan-duc

Post on 20-Mar-2017

17 views

Category:

Software


1 download

TRANSCRIPT

Page 1: 004. Working with React component

004. WORKING WITH REACT COMPONENT

Presenter: Binh Quan

Page 2: 004. Working with React component

ReactJS - Components

❖ File/Folder Structure❖ Create a React Component❖ Bootstrapping a React project❖ JSX in React❖ Component Lifecycle❖ Stateless Component❖ Events

Remind from previous lesson

Page 3: 004. Working with React component

ReactJS - Components

❖ Passing Props❖ Property Type Checking❖ Default Props❖ Context❖ Accessing Components❖ Types of Components❖ Bonus: React Chrome extension

Page 4: 004. Working with React component

Passing props

UserPage.jsx User.jsx

Page 5: 004. Working with React component

Prop Type Checking

Page 6: 004. Working with React component

Prop Type Checking

Prop Types

❖ array❖ bool❖ Func❖ Number❖ Object❖ String❖ Symbol

❖ Element❖ instanceOf(<type>)❖ oneOf([array])❖ oneOfType([arrayOfTypes]

)❖ arrayOf(<type>)❖ objectOf(<type>)❖ shape(shapeObject)

See more: https://facebook.github.io/react/docs/typechecking-with-proptypes.html

Page 7: 004. Working with React component

Default Props

Page 8: 004. Working with React component

Context

Page 9: 004. Working with React component

Refs and the DOM

Use ref as callback Use ref as reference name

Page 10: 004. Working with React component

Dump❖ DO bind to DOM

events❖ DO use ref so that

event bindings can fetch data from the DOM and pass it up to parent callbacks.

❖ DO have data in state

❖ DO bind to changes in Stores

❖ DO call Actions to make changes to data

❖ DO pass data to children components as props

❖ Smart Components rules, plus:

❖ DO know about url routes

Smart PagesTypes of Component

❖ DO NOT use state for data (UI behaviors only)

❖ DO NOT know about Stores

❖ DO NOT know about url routes or what page they are on

❖ DO NOT know about the generated DOM in child components

Reusability

Page 11: 004. Working with React component

ReactJS - File/Folder Structure

Page 12: 004. Working with React component

Now Demo