fullstack js workshop

85
Fullstack JS Workshop Front End Session Mar 5th, 2017 @ Fak MIPA UGM

Upload: muhammad-rizki-rijal

Post on 19-Mar-2017

228 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Fullstack JS Workshop

Fullstack JS WorkshopFront End Session

Mar 5th, 2017 @ Fak MIPA UGM

Page 2: Fullstack JS Workshop

About Me

Page 3: Fullstack JS Workshop

Muhammad Rizki RijalJS dev @wonderlabs, JS Enthusiast

Page 4: Fullstack JS Workshop

React JS

Page 5: Fullstack JS Workshop

Why we use react?

Page 6: Fullstack JS Workshop

coz it’s cool right?ps: and hype

Page 7: Fullstack JS Workshop

What is React?

Page 8: Fullstack JS Workshop

It’s super cool UI library right?

Page 9: Fullstack JS Workshop

React is a JavaScript library for building user interfaces.

Page 10: Fullstack JS Workshop

Declarative

Component-based

Learn once, write anywhere

Page 11: Fullstack JS Workshop

Declarative

Component-based

Learn once, write anywhere

Page 12: Fullstack JS Workshop

I want a fancy button, when it get clicked its color and text will be changing back and

forth

Page 13: Fullstack JS Workshop

Imperative Way

Page 14: Fullstack JS Workshop

Declarative Way

Page 15: Fullstack JS Workshop

Declarative

Component-based

Learn once, write anywhere

Page 16: Fullstack JS Workshop
Page 17: Fullstack JS Workshop

Declarative

Component-based

Learn once, write anywhere

Page 18: Fullstack JS Workshop

https://engineering.instagram.com/react-native-at-instagram-dd828a9a90c7#.bj6xlq84o

Page 19: Fullstack JS Workshop

Super Stupidly Simple React App

Page 20: Fullstack JS Workshop
Page 21: Fullstack JS Workshop

JSX (HTML in JS?)

Page 22: Fullstack JS Workshop
Page 23: Fullstack JS Workshop
Page 24: Fullstack JS Workshop

Embedding Expression

Specifying Attributes

Specifying Children

Page 25: Fullstack JS Workshop

Embedding Expression

Specifying Attributes

Specifying Children

Page 26: Fullstack JS Workshop

ProductItem.js

ProductItem.css

Page 27: Fullstack JS Workshop
Page 28: Fullstack JS Workshop

Embedding Expression

Specifying Attributes

Specifying Children

Page 29: Fullstack JS Workshop
Page 30: Fullstack JS Workshop

Embedding Expression

Specifying Attributes

Specifying Children

Page 31: Fullstack JS Workshop
Page 32: Fullstack JS Workshop

All About Components

Page 33: Fullstack JS Workshop
Page 34: Fullstack JS Workshop

Class Component

Page 35: Fullstack JS Workshop

Functional Component

Page 36: Fullstack JS Workshop
Page 37: Fullstack JS Workshop

<CommentList />

Page 38: Fullstack JS Workshop

<Comment />

<Comment />

<CommentList />

Page 39: Fullstack JS Workshop

<User />

<User />

<Comment />

<Comment />

<CommentList />

Page 42: Fullstack JS Workshop

<User />

<User />

Page 44: Fullstack JS Workshop

<Comment />

<Comment />

<User />

<User />

Page 46: Fullstack JS Workshop

<CommentList />

<Comment />

<Comment />

<User />

<User />

Page 48: Fullstack JS Workshop

Props & State

Page 49: Fullstack JS Workshop

Basically react has two types of data, props and state

Page 50: Fullstack JS Workshop

Props is read-only dataAlso it can be used to pass an event/data change handler

Page 51: Fullstack JS Workshop
Page 52: Fullstack JS Workshop

State is where to store data that is going to change

Page 53: Fullstack JS Workshop
Page 54: Fullstack JS Workshop

later on we can update component’s state with

setState()

Page 55: Fullstack JS Workshop
Page 56: Fullstack JS Workshop

Data Flow

Page 57: Fullstack JS Workshop
Page 62: Fullstack JS Workshop
Page 64: Fullstack JS Workshop

Component Life Cycle Hooks

Page 65: Fullstack JS Workshop

Think of it like your daily schedule

Page 66: Fullstack JS Workshop

Mounting

- constructor(props)

- componentWillMount()

- componentDidMount()

Page 67: Fullstack JS Workshop

Updating

- componentWillReceiveProps(nextProps, prevProps)

- shouldComponentUpdate(nextProps, nextState)

- componentWillUpdate(nextProps, nextState)

- componentDidUpdate()

Page 68: Fullstack JS Workshop

Unmounting

- componentWillUnmount()

Page 69: Fullstack JS Workshop

What We Gonna Build

Page 70: Fullstack JS Workshop
Page 71: Fullstack JS Workshop

Folder Structure

/chat-bot /node_modules /public index.html /src /components /pages /lib App.css App.js index.css index.js package.json

Page 72: Fullstack JS Workshop
Page 73: Fullstack JS Workshop

<Navbar />

Page 74: Fullstack JS Workshop

<Navbar />

<ChatWindow />

Page 75: Fullstack JS Workshop

<Navbar />

<ChatWindow />

<MessageInput />

Page 76: Fullstack JS Workshop

<Navbar />

<ChatWindow />

<MessageInput />

<MessageList />

Page 77: Fullstack JS Workshop

<Navbar />

<ChatWindow />

<MessageInput />

<MessageList />

<Message />

Page 78: Fullstack JS Workshop

<Navbar />

<ChatWindow />

<MessageInput />

<MessageList />

<Message />

<App />

Page 79: Fullstack JS Workshop

Let’s get started!

Page 80: Fullstack JS Workshop

Clone UI Template

https://github.com/wonderlabshq/js-workshop-html

Page 81: Fullstack JS Workshop

Dependencies

- Create React App

$ npm i -g create-react-app

$ npm i -S moment axios

- Moment (for date creation and formatting)

- Axios(Perform request to backend)

Page 82: Fullstack JS Workshop

App Component State Schema

{

messages: [

{

“author”: “Me”, // “Me” or “Bot”

“text”: “Hello!”, // Message body

“createdAt”: “Sat Mar 04 2017 20:11:00 GMT+0700 (WIB)”,

}

]

}

Page 83: Fullstack JS Workshop

Things To Discover Next

- React Router

- Redux

- React Thunk / React Saga / React Observables

- Testing

- Webpack

Page 84: Fullstack JS Workshop

Sourcehttps://facebook.github.io/reacthttps://tylermcginnis.com/imperative-vs-declarative-programming/

Page 85: Fullstack JS Workshop

Thanks!