i heard react was good

71
HI!

Upload: fitc

Post on 22-Jan-2018

265 views

Category:

Internet


2 download

TRANSCRIPT

Page 1: I Heard React Was Good

HI!

Page 2: I Heard React Was Good

ABOUT MELead Instructor and Developer at HackerYou

@Rchristiani on Twitter

ryanchristiani.com

letslearnes6.com

Page 3: I Heard React Was Good
Page 4: I Heard React Was Good

I HEARD REACT WAS GOOD

Page 5: I Heard React Was Good
Page 6: I Heard React Was Good

REACT AT HACKERYOUInternal Applications

Alumni

Page 7: I Heard React Was Good

CONSIDERATIONS AS A TEACHERReact is the new AngularJS in terms of job posting, what

does that mean for us?

Students are getting jobs using React.

Page 8: I Heard React Was Good

INFORMS HOW WE TEACHWhen students start exploring frameworks and libraries so

early on, this starts to change how we teach.

Page 9: I Heard React Was Good

WHY DO WE HAVE REACT?We have a lot of libraries and frameworks...

Page 10: I Heard React Was Good

Ember

Angular

Backbone

Vue.js

Mithril

Tesla...

I thought I made that one up, I googled it, it is a thing...

Page 11: I Heard React Was Good

MVC DREAMSWe have so many frameworks that follow an MVC or MV*pattern. The goal of all of them is to create structure and

organization.

Page 12: I Heard React Was Good

SOME ARE OPINIONATED.

Page 13: I Heard React Was Good

SOME ARE NOT.

Page 14: I Heard React Was Good

REACT IS JUST A VIEW LAYERThe one key feature of the React library, is that it is really just

a view layer, mostly simple components.let App = React.createClass({ render() { return ( <main> <h1>What an APP!</h1> </main> ); } });

Page 15: I Heard React Was Good

Since React is just a view layer, it is more of block in yourapplication stack, rather than the entire application

structure itself. You have freedom to build as you need.

Page 16: I Heard React Was Good

COMPONENTS REIGN SUPREMEComponents allow you to look at your app in a modular, DRYand reusable manner. Large templates can be broken down

into simple, reusable components.

Page 17: I Heard React Was Good
Page 18: I Heard React Was Good

REUSABLElet Avatar = React.createClass({ render() { let imageUrl = (() => { let email = this.props.email; let size = this.props.size || 200; if(email) { return 'https://www.gravatar.com/avatar/' + md5(email) + '?s=' + size; } })(); return ( <img className="avatar" src={imageUrl} alt="" /> ); } });

Page 19: I Heard React Was Good

<li> <AvatarImage email={this.state.user.email} size="50" /> {this.state.user.name} </li>

Page 20: I Heard React Was Good

PROPS<AvatarImage email={this.state.user.email} size="50" />

Props allow us to create nice composable components.

Page 21: I Heard React Was Good

NOT JUST REACTReact is not the only library focusing on components,

libraries like Polymer and frameworks like Ember havesimilar structures.

Polymer is all about components, the styles and events areall wrapper up into one file. One component.

Page 22: I Heard React Was Good

LIFECYCLESEach component has a lifecycle. This lifecycle allows you to

really take control of your components. These will run atcertain points through the execution of the component.

Page 23: I Heard React Was Good

COMPONENTDIDMOUNT()

This is a hook that will run when the component is rendered,and it will run only once. But here is where we can decide

whether or not to load data.

Page 24: I Heard React Was Good

COMPONENTWILLUNMOUNT()

A hook run before the component is unmounted, orremoved. A place to clean up if needed.

This reminded me of Backbone, when you had to manuallyclean up a�er yourself.

Page 25: I Heard React Was Good

COMPONENTS MAKE TESTING EASY.Because everything is broken up into modular parts, this

allows you to isolate your components to test them.

Page 26: I Heard React Was Good

//avatar.js export default React.createClass({ ... });

//avatar-test.js import Avatar from './components/avatar.js';

Page 27: I Heard React Was Good

DON'T NEED ANYTHING FANCY?Use a stateless component.

const UserName = (props) => { return ( <h3>{props.userName}</h3> ) };

//Useage <UserName userName="Ryan Christiani" />

Page 28: I Heard React Was Good

In general components are pretty loosely coupled, they arefairly self contained. Typically they are coupled most with

the data coming into them in the form of props.

Page 29: I Heard React Was Good

JSX

Page 30: I Heard React Was Good

HTML in your JavaScript?!

Seems weird at first.

Create a more intuitive templates.

Page 31: I Heard React Was Good

ALLOWS DESIGNERS TO GET INVOLVED WITHTHE PROCESS

Page 32: I Heard React Was Good

Attach your events on the DOM....

Page 33: I Heard React Was Good

EVENTS IN YOUR TEMPLATESSeems counter intuitive, a�er all didn't we all learn to

decouple events from the DOM?

Creating declarative events on the DOM, since everythingcan exist in one file, makes it easy to track down your events

and understand your logic.

Page 34: I Heard React Was Good

let User = React.createClass({ delete() { //Delete the user }, render() { return ( <div> ... <button onclick="{this.delete}">Delete User</button> </div> ) } });

Page 35: I Heard React Was Good

The structure is becoming increasing more dynamic.Keeping our events tied to this structure now makes more

sense.

Page 36: I Heard React Was Good

LACK OF FEATURES

Page 37: I Heard React Was Good

React provides us with great building blocks, but it does notprovide all the pieces. This is on purpose.

...I think that can be a good thing, more on that later

Page 38: I Heard React Was Good

NO CLEAR PATH.However that can be confusing. When you start working with

Angular, or Ember. There is a real ${library.name}-way of doing things.

little ES6 joke there...

Page 39: I Heard React Was Good

HOW DO YOU START A PROJECT?Since React is just one layer of your app, how do you get

started?

Page 40: I Heard React Was Good

WEBPACK?

GULP + BROWSERIFY?

NPM SCRIPTS?

BABELIFY?!

GRUNT? JUST GOT A V1 RELEASE!

Page 41: I Heard React Was Good

THE EMBER WAYIf you have ever worked with Ember, you know there is a

very Ember way to do things.

Ember has the ember-cli as a great tool to get going with!

Page 42: I Heard React Was Good

ember new app

Page 43: I Heard React Was Good

ember generate component user

Page 44: I Heard React Was Good

react-cli

rackt-cli

Build your own?

Page 45: I Heard React Was Good

There is no set structure for a React app

Page 46: I Heard React Was Good

DATAOne of the first things you will want when working with

React is getting data.

Page 47: I Heard React Was Good

WHERE DOES IT COME FROM?Most frameworks have a preferred method of getting data.

Ember has Ember Data.

Angular has $http

Backbone has Backbone.Model and Backbone.Collection

Page 48: I Heard React Was Good

React has what?

Page 49: I Heard React Was Good

$.ajax

Page 50: I Heard React Was Good

fetch(They finally made that happen)

Page 51: I Heard React Was Good

Roll your own?

Page 52: I Heard React Was Good

IT'S UP TO YOU!

Page 53: I Heard React Was Good

APPLICATION FLOW.How do we handle data at an application level?

Page 54: I Heard React Was Good

REACT IS NOT AN MVC FRAMEWORK

Page 55: I Heard React Was Good

FLUXFacebook's proposed application architecture.

...but not an actual implementation

Page 56: I Heard React Was Good
Page 57: I Heard React Was Good

REDUX

Page 58: I Heard React Was Good

RELAYGRAPHQL

Page 59: I Heard React Was Good

GOOD PARTS

Page 60: I Heard React Was Good

SPEEDReact is FAST!

And this has pushed frameworks like Ember even further!Ember implemented its Glimmer engine based off of ideas

from React.

Page 61: I Heard React Was Good

FORCES EXPLORATIONBecause there are missing pieces, it forces you or your team

to explore other possibilities.

What practices work best for you, each project will have adifferent set of requirements.

Page 62: I Heard React Was Good

CREATES BETTER JS DEVSIt is helping to create better JS devs, not better

`${framework} devs`.

Too o�en I see people getting stuck as a framework specificdeveloper, and not expanding on their core skills.

Page 63: I Heard React Was Good
Page 64: I Heard React Was Good

INTRO TO ES6letslearnes6.com

Page 65: I Heard React Was Good

FUNCTIONAL PROGRAMMING

Page 66: I Heard React Was Good

IMMUTABILITY

Page 67: I Heard React Was Good

PEOPLE GET AFRAID OF POSSIBILITIES.IT IS IMPORTANT TO REMEMBER.

Page 68: I Heard React Was Good
Page 69: I Heard React Was Good
Page 70: I Heard React Was Good

You don't need it all.

Page 71: I Heard React Was Good

THANKS@Rchristiani