SlideShare a Scribd company logo
Hasan @ DEV6 – #WEBU17
?
Hasan @ DEV6 – #WEBU17
Hasan @ DEV6 – #WEBU17
Hasan Ahmad
Senior Consultant @ DEV6
Lead @ DevC Toronto
https://www.dev6.com/
https://www.facebook.com/groups/DevCToronto/
Hasan @ DEV6 – #WEBU17
Front-end frameworks have more in common than you might expect
Component based architecture
View-Model / State management
Routing views with URLs
Hasan @ DEV6 – #WEBU17
Components
Angular: Decorate classes with component life-cycle hooks
React: ES6 inheritance provides interfaces for life-cycle hooks
Hasan @ DEV6 – #WEBU17
@Component({selector:	'greet',	template:	'Hello	{{name}}!’})		
class	Greet	{		
	name:	string	=	'World';	
}	
class	Welcome	extends	React.component	{	
	render()	{		
	 	return	<h1>Hello,	{this.props.name}</h1>		
	}		
}
Hasan @ DEV6 – #WEBU17
ngOnChanges()	–	when	a	data	binding	has	changed	
ngOnInit()	–	when	angular	has	already	displayed	bound	data	
ngOnCheck()	–	manual	change	detection	
ngAfterContentInit()	-	…	
ngAfterContentInitChecked()	-	…	
ngAfterViewInit()	-	…	
ngAfterViewInitChecked()	-	…	
ngOnDestroy()	–	right	before	angular	removes	a	component
Hasan @ DEV6 – #WEBU17
constructor()	–	component	is	created	
componentWillMount()	–	before	a	component	has	been	attached	to	view	
render()	–	return	the	react	view	element	
componentDidMount()	–	after	react	has	attached	component	to	view	
componentWillRecieveProps()	-	…	
shouldComponentUpdate()	-	…	
componentWillUpdate()	-	…	
componentDidUpdate()	-	after	react	has	updated	a	component	
componentWillUnmount()	–	before	react	removes	a	component
Hasan @ DEV6 – #WEBU17
export	class	PeekABoo	implements	OnInit	{	
	constructor(private	logger:	LoggerService)	{	}	
	//	implement	OnInit's	`ngOnInit`	method	
	ngOnInit()	{	
	 	this.logIt(`OnInit`);		
	}		
	logIt(msg:	string)	{		
	 	this.logger.log(`#${nextId++}	${msg}`);		
	}	
}
Hasan @ DEV6 – #WEBU17
class	Clock	extends	React.Component	{	
constructor(props)	{		
super(props);		
this.state	=	{date:	new	Date()};		
}	
componentDidMount()	{		
	this.timerID	=	setInterval(	()	=>	this.tick(),	1000	);		
}	
componentWillUnmount()	{		
	clearInterval(this.timerID);		
}		
//...		
}
Hasan @ DEV6 – #WEBU17
Data Binding
Angular - flexible data binding options, including two-way
React - One-way data binding, lift state up
Hasan @ DEV6 – #WEBU17
Component to
DOM
Interpolation and Property Binding
One-way binding: Value goes from component data property to a target
element property
DOM to
Component
Event Binding: user interacted with page, bring that back to the component
Both Two-Way Binding: update data as soon as it has been changed by the user
Hasan @ DEV6 – #WEBU17
Handling State
Angular – Mutable data, services as singletons (can opt for immutable too)
React – state & props, flux, redux
Hasan @ DEV6 – #WEBU17
Service is a singleton – only one instance in memory
Components can mutate data in services, everyone who injects a
service can see the altered state
Angular will automatically re-draw the UI with the new data
(Change Detection + Zones + Data Binding)
Hasan @ DEV6 – #WEBU17
Components have their own state, react renders components when
their state changes
By default, you have to maintain parent-child relationships to state,
using props
redux: have one giant state object
Hasan @ DEV6 – #WEBU17
Store Single big JSON, all state for entire application
Reducer Update store, return a new state
Action Dispatched to trigger a state change
Follow up on redux.js.org
Hasan @ DEV6 – #WEBU17
Layout & Styling
Angular has embraced Shadow DOM +View Encapsulation for styling
components
React is compatible with many styling approaches: traditional CSS,
bootstrap, and flexbox
Hasan @ DEV6 – #WEBU17
@Component({		
selector:	'hero-details',		
template:	`		
<h2>{{hero.name}}</h2>		
<hero-team	[hero]=hero></hero-team>		
<ng-content></ng-content>		
`,		
styleUrls:	['app/hero-details.component.css']		
})	
export	class	HeroDetailsComponent	{	/*	.	.	.	*/	}
Hasan @ DEV6 – #WEBU17
What is Shadow DOM?
Shadow DOM is included in the Web Components standard by W3C
Refers to the ability to include a subtree of DOM elements
Allows DOM implementation to be hidden from the rest of the
document
Hasan @ DEV6 – #WEBU17
<hero-details	_nghost-pmm-5>	
<h2	_ngcontent-pmm-5>Mister	Fantastic</h2>		
<hero-team	_ngcontent-pmm-5	_nghost-pmm-6>		
	<h3	_ngcontent-pmm-6>Team</h3>		
</hero-team>		
</hero-detail>
Hasan @ DEV6 – #WEBU17
render(props,	context)	{		
	const	notes	=	this.props.notes;		
	return	<ul	className='notes'>{notes.map(this.renderNote)}</ul>;	
}	
render(props,	context)	{		
	const	notes	=	this.props.notes;		
	const	style	=	{		
	 	margin:	'0.5em',		
	 	paddingLeft:	0,		
	 	listStyle:	'none'		
	};		
	return	<ul	style={style}>{notes.map(this.renderNote)}</ul>;		
}	
https://survivejs.com/react/advanced-techniques/styling-react/
Hasan @ DEV6 – #WEBU17
import	React	from	'react'		
import	injectSheet	from	'react-jss'		
const	styles	=	{		
	button:	{		
	 	background:	props	=>	props.color	},		
	label:	{		
	 	fontWeight:	'bold'		
	}		
}		
const	Button	=	({classes,	children})	=>	(		
	<button	className={classes.button}>		
	 	<span	className={classes.label}>		
	 	 	{children}		
	 	</span>		
	</button>		
)		
export	default	injectSheet(styles)(Button)	
https://github.com/cssinjs/jss
Hasan @ DEV6 – #WEBU17
var	Block	=	require('jsxstyle/Block');		
var	React	=	require('react');		
var	MyComponent	=	React.createClass({		
render:	function()	{		
	return	<Block	color="red">Hello,	world!</Block>;		
}		
});	
https://github.com/smyte/jsxstyle
Hasan @ DEV6 – #WEBU17
Routing
Angular has one routing model, driven by the URL
@angular/router is engineered for many scenarios
React has many different options, depending on your app architecture
react-router, fluxxor-react-router, react-redux-router
Hasan @ DEV6 – #WEBU17
template:	`		
<h1>Angular	Router</h1>		
<nav>		
<a	routerLink="/crisis-center"	routerLinkActive="active">Crisis	Center</a>		
<a	routerLink="/heroes"	routerLinkActive="active">Heroes</a>		
</nav>		
<router-outlet></router-outlet>		
`	
const	appRoutes:	Routes	=	[		
{	path:	'crisis-center',	component:	CrisisListComponent	},		
{	path:	'hero/:id',	component:	HeroDetailComponent	},		
{	path:	'heroes',	component:	HeroListComponent,	data:	{	title:	'Heroes	List'	}	},		
{	path:	'',	redirectTo:	'/heroes',	pathMatch:	'full'	},		
{	path:	'**',	component:	PageNotFoundComponent	}		
];
Hasan @ DEV6 – #WEBU17
//	./src/index.jsx		
import	React,	{	Component	}	from	'react';		
import	{	render	}	from	'react-dom';		
//	Import	routing	components		
import	{Router,	Route}	from	'react-router';		
class	Home	extends	Component	{		
render(){		
	return	(<h1>Hi</h1>);		
}		
}	
render(		
	<Router>		
	 	<!--Each	route	is	defined	with	Route-->		
	 	<Route	path="/"	component={Home}/>		
	</Router>,		
	document.getElementById('container')		
);	
https://scotch.io/tutorials/routing-react-apps-the-complete-guide
Hasan @ DEV6 – #WEBU17
import	React	from	'react'		
import	ReactDOM	from	'react-dom'		
import	{	createStore,	combineReducers	}	from	'redux'		
import	{	Provider	}	from	'react-redux'		
import	{	Router,	Route,	browserHistory	}	from	'react-router'		
import	{	syncHistoryWithStore,	routerReducer	}	from	'react-router-redux'		
import	reducers	from	'<project-path>/reducers'		
const	store	=	createStore(	combineReducers({	...reducers,	routing:	routerReducer	})	)		
//	Create	an	enhanced	history	that	syncs	navigation	events	with	the	store		
const	history	=	syncHistoryWithStore(browserHistory,	store)		
ReactDOM.render(		
<Provider	store={store}>		
<Router	history={history}>		
<Route	path="/"	component={App}>		
<Route	path="foo"	component={Foo}/>		
<Route	path="bar"	component={Bar}/>		
</Route>		
</Router>		
</Provider>,		
document.getElementById('mount')		
)	
https://github.com/reactjs/react-router-redux
Hasan @ DEV6 – #WEBU17
Testing
Angular comes with extensive support for jasmine with karma and
protractor
React varies by project, some use Jest, others use Mocha/Chai/Enzyme
Hasan @ DEV6 – #WEBU17
Cross-platform apps
Extend cross platform experience beyond the browser
Progressive Web Applications
Cordova / Hybrid Applications
NativeScript / React Native
Hasan @ DEV6 – #WEBU17
Angular + React = ?
react-native-renderer – Angular project in a react native app
ng-redux – Use redux (popularized by React) in your Angular projects
Hasan @ DEV6 – #WEBU17
Summary
Equal, yet different:Two approaches to solving common problems all
developers face.
Choice between Angular and React is ultimately driven by an
organization’s development philosophy.
Hasan @ DEV6 – #WEBU17
ThankYou!
Questions?

More Related Content

What's hot (20)

PDF
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
IT Event
 
PDF
Booting up with polymer
Marcus Hellberg
 
PDF
jQuery 1.9 and 2.0 - Present and Future
Richard Worth
 
PDF
Booting up with polymer
Marcus Hellberg
 
PDF
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
David Kaneda
 
PDF
Building a Secure App with Google Polymer and Java / Spring
sdeeg
 
PPTX
Disrupting the application eco system with progressive web applications
Chris Love
 
PDF
AtlasCamp 2015: Using add-ons to build add-ons
Atlassian
 
PPT
You Know WebOS
360|Conferences
 
PDF
Unlock the next era of UI design with Polymer
Rob Dodson
 
PDF
Building an HTML5 Video Player
Jim Jeffers
 
PDF
AspNetWhitePaper
tutorialsruby
 
PDF
Usability in the GeoWeb
Dave Bouwman
 
PPTX
Enough with the JavaScript already!
Nicholas Zakas
 
PDF
Enjoy the vue.js
TechExeter
 
PDF
Externalizing Chatter Using Heroku, Angular.js, Node.js and Chatter REST APIs
Salesforce Developers
 
PDF
The Complementarity of React and Web Components
Andrew Rota
 
PDF
HTML5 and the dawn of rich mobile web applications
James Pearce
 
PDF
Modern Web Application Development Workflow - EclipseCon Europe 2014
Stéphane Bégaudeau
 
PDF
Our application got popular and now it breaks
ColdFusionConference
 
Oleh Zasadnyy "Progressive Web Apps: line between web and native apps become ...
IT Event
 
Booting up with polymer
Marcus Hellberg
 
jQuery 1.9 and 2.0 - Present and Future
Richard Worth
 
Booting up with polymer
Marcus Hellberg
 
How to Develop a Rich, Native-quality User Experience for Mobile Using Web St...
David Kaneda
 
Building a Secure App with Google Polymer and Java / Spring
sdeeg
 
Disrupting the application eco system with progressive web applications
Chris Love
 
AtlasCamp 2015: Using add-ons to build add-ons
Atlassian
 
You Know WebOS
360|Conferences
 
Unlock the next era of UI design with Polymer
Rob Dodson
 
Building an HTML5 Video Player
Jim Jeffers
 
AspNetWhitePaper
tutorialsruby
 
Usability in the GeoWeb
Dave Bouwman
 
Enough with the JavaScript already!
Nicholas Zakas
 
Enjoy the vue.js
TechExeter
 
Externalizing Chatter Using Heroku, Angular.js, Node.js and Chatter REST APIs
Salesforce Developers
 
The Complementarity of React and Web Components
Andrew Rota
 
HTML5 and the dawn of rich mobile web applications
James Pearce
 
Modern Web Application Development Workflow - EclipseCon Europe 2014
Stéphane Bégaudeau
 
Our application got popular and now it breaks
ColdFusionConference
 

Similar to Angular vs React for Web Application Development (20)

PDF
Nuxt.JS Introdruction
David Ličen
 
PDF
Front End Development for Back End Developers - Devoxx UK 2017
Matt Raible
 
PPTX
Html5
Chris Young
 
PPTX
Html5 & less css
Graham Johnson
 
PPTX
How i made the responsive mobile version of
Sayed Ahmed
 
PPTX
An introduction to Vue.js
Pagepro
 
PPT
ReactJS.ppt
MOMEKEMKUEFOUETDUREL
 
PDF
AngularJS 101 - Everything you need to know to get started
Stéphane Bégaudeau
 
PDF
Leveraging the Power of Custom Elements in Gutenberg
Felix Arntz
 
PDF
ReactJS vs AngularJS - Head to Head comparison
500Tech
 
PPTX
Getting Started with React v16
Benny Neugebauer
 
PDF
[Bristol WordPress] Supercharging WordPress Development
Adam Tomat
 
PDF
Ajax Performance Tuning and Best Practices
Doris Chen
 
PPTX
crtical points for customizing Joomla templates
amit das
 
PDF
Node.js & Twitter Bootstrap Crash Course
Aaron Silverman
 
PPTX
Nodejs.meetup
Vivian S. Zhang
 
PPTX
The future of web development write once, run everywhere with angular.js and ...
Mark Roden
 
PDF
The future of web development write once, run everywhere with angular js an...
Mark Leusink
 
PDF
Web Components v1
Mike Wilcox
 
KEY
It's a Mod World - A Practical Guide to Rocking Modernizr
Michael Enslow
 
Nuxt.JS Introdruction
David Ličen
 
Front End Development for Back End Developers - Devoxx UK 2017
Matt Raible
 
Html5 & less css
Graham Johnson
 
How i made the responsive mobile version of
Sayed Ahmed
 
An introduction to Vue.js
Pagepro
 
AngularJS 101 - Everything you need to know to get started
Stéphane Bégaudeau
 
Leveraging the Power of Custom Elements in Gutenberg
Felix Arntz
 
ReactJS vs AngularJS - Head to Head comparison
500Tech
 
Getting Started with React v16
Benny Neugebauer
 
[Bristol WordPress] Supercharging WordPress Development
Adam Tomat
 
Ajax Performance Tuning and Best Practices
Doris Chen
 
crtical points for customizing Joomla templates
amit das
 
Node.js & Twitter Bootstrap Crash Course
Aaron Silverman
 
Nodejs.meetup
Vivian S. Zhang
 
The future of web development write once, run everywhere with angular.js and ...
Mark Roden
 
The future of web development write once, run everywhere with angular js an...
Mark Leusink
 
Web Components v1
Mike Wilcox
 
It's a Mod World - A Practical Guide to Rocking Modernizr
Michael Enslow
 
Ad

More from FITC (20)

PPTX
Cut it up
FITC
 
PDF
Designing for Digital Health
FITC
 
PDF
Profiling JavaScript Performance
FITC
 
PPTX
Surviving Your Tech Stack
FITC
 
PDF
How to Pitch Your First AR Project
FITC
 
PDF
Start by Understanding the Problem, Not by Delivering the Answer
FITC
 
PDF
Cocaine to Carrots: The Art of Telling Someone Else’s Story
FITC
 
PDF
Everyday Innovation
FITC
 
PDF
HyperLight Websites
FITC
 
PDF
Everything is Terrifying
FITC
 
PDF
Post-Earth Visions: Designing for Space and the Future Human
FITC
 
PDF
The Rise of the Creative Social Influencer (and How to Become One)
FITC
 
PDF
East of the Rockies: Developing an AR Game
FITC
 
PDF
Creating a Proactive Healthcare System
FITC
 
PDF
World Transformation: The Secret Agenda of Product Design
FITC
 
PDF
The Power of Now
FITC
 
PDF
High Performance PWAs
FITC
 
PDF
Rise of the JAMstack
FITC
 
PDF
From Closed to Open: A Journey of Self Discovery
FITC
 
PDF
Projects Ain’t Nobody Got Time For
FITC
 
Cut it up
FITC
 
Designing for Digital Health
FITC
 
Profiling JavaScript Performance
FITC
 
Surviving Your Tech Stack
FITC
 
How to Pitch Your First AR Project
FITC
 
Start by Understanding the Problem, Not by Delivering the Answer
FITC
 
Cocaine to Carrots: The Art of Telling Someone Else’s Story
FITC
 
Everyday Innovation
FITC
 
HyperLight Websites
FITC
 
Everything is Terrifying
FITC
 
Post-Earth Visions: Designing for Space and the Future Human
FITC
 
The Rise of the Creative Social Influencer (and How to Become One)
FITC
 
East of the Rockies: Developing an AR Game
FITC
 
Creating a Proactive Healthcare System
FITC
 
World Transformation: The Secret Agenda of Product Design
FITC
 
The Power of Now
FITC
 
High Performance PWAs
FITC
 
Rise of the JAMstack
FITC
 
From Closed to Open: A Journey of Self Discovery
FITC
 
Projects Ain’t Nobody Got Time For
FITC
 
Ad

Recently uploaded (20)

PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
July Patch Tuesday
Ivanti
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
July Patch Tuesday
Ivanti
 

Angular vs React for Web Application Development

  • 1. Hasan @ DEV6 – #WEBU17 ?
  • 2. Hasan @ DEV6 – #WEBU17
  • 3. Hasan @ DEV6 – #WEBU17 Hasan Ahmad Senior Consultant @ DEV6 Lead @ DevC Toronto https://www.dev6.com/ https://www.facebook.com/groups/DevCToronto/
  • 4. Hasan @ DEV6 – #WEBU17 Front-end frameworks have more in common than you might expect Component based architecture View-Model / State management Routing views with URLs
  • 5. Hasan @ DEV6 – #WEBU17 Components Angular: Decorate classes with component life-cycle hooks React: ES6 inheritance provides interfaces for life-cycle hooks
  • 6. Hasan @ DEV6 – #WEBU17 @Component({selector: 'greet', template: 'Hello {{name}}!’}) class Greet { name: string = 'World'; } class Welcome extends React.component { render() { return <h1>Hello, {this.props.name}</h1> } }
  • 7. Hasan @ DEV6 – #WEBU17 ngOnChanges() – when a data binding has changed ngOnInit() – when angular has already displayed bound data ngOnCheck() – manual change detection ngAfterContentInit() - … ngAfterContentInitChecked() - … ngAfterViewInit() - … ngAfterViewInitChecked() - … ngOnDestroy() – right before angular removes a component
  • 8. Hasan @ DEV6 – #WEBU17 constructor() – component is created componentWillMount() – before a component has been attached to view render() – return the react view element componentDidMount() – after react has attached component to view componentWillRecieveProps() - … shouldComponentUpdate() - … componentWillUpdate() - … componentDidUpdate() - after react has updated a component componentWillUnmount() – before react removes a component
  • 9. Hasan @ DEV6 – #WEBU17 export class PeekABoo implements OnInit { constructor(private logger: LoggerService) { } // implement OnInit's `ngOnInit` method ngOnInit() { this.logIt(`OnInit`); } logIt(msg: string) { this.logger.log(`#${nextId++} ${msg}`); } }
  • 10. Hasan @ DEV6 – #WEBU17 class Clock extends React.Component { constructor(props) { super(props); this.state = {date: new Date()}; } componentDidMount() { this.timerID = setInterval( () => this.tick(), 1000 ); } componentWillUnmount() { clearInterval(this.timerID); } //... }
  • 11. Hasan @ DEV6 – #WEBU17 Data Binding Angular - flexible data binding options, including two-way React - One-way data binding, lift state up
  • 12. Hasan @ DEV6 – #WEBU17 Component to DOM Interpolation and Property Binding One-way binding: Value goes from component data property to a target element property DOM to Component Event Binding: user interacted with page, bring that back to the component Both Two-Way Binding: update data as soon as it has been changed by the user
  • 13. Hasan @ DEV6 – #WEBU17 Handling State Angular – Mutable data, services as singletons (can opt for immutable too) React – state & props, flux, redux
  • 14. Hasan @ DEV6 – #WEBU17 Service is a singleton – only one instance in memory Components can mutate data in services, everyone who injects a service can see the altered state Angular will automatically re-draw the UI with the new data (Change Detection + Zones + Data Binding)
  • 15. Hasan @ DEV6 – #WEBU17 Components have their own state, react renders components when their state changes By default, you have to maintain parent-child relationships to state, using props redux: have one giant state object
  • 16. Hasan @ DEV6 – #WEBU17 Store Single big JSON, all state for entire application Reducer Update store, return a new state Action Dispatched to trigger a state change Follow up on redux.js.org
  • 17. Hasan @ DEV6 – #WEBU17 Layout & Styling Angular has embraced Shadow DOM +View Encapsulation for styling components React is compatible with many styling approaches: traditional CSS, bootstrap, and flexbox
  • 18. Hasan @ DEV6 – #WEBU17 @Component({ selector: 'hero-details', template: ` <h2>{{hero.name}}</h2> <hero-team [hero]=hero></hero-team> <ng-content></ng-content> `, styleUrls: ['app/hero-details.component.css'] }) export class HeroDetailsComponent { /* . . . */ }
  • 19. Hasan @ DEV6 – #WEBU17 What is Shadow DOM? Shadow DOM is included in the Web Components standard by W3C Refers to the ability to include a subtree of DOM elements Allows DOM implementation to be hidden from the rest of the document
  • 20. Hasan @ DEV6 – #WEBU17 <hero-details _nghost-pmm-5> <h2 _ngcontent-pmm-5>Mister Fantastic</h2> <hero-team _ngcontent-pmm-5 _nghost-pmm-6> <h3 _ngcontent-pmm-6>Team</h3> </hero-team> </hero-detail>
  • 21. Hasan @ DEV6 – #WEBU17 render(props, context) { const notes = this.props.notes; return <ul className='notes'>{notes.map(this.renderNote)}</ul>; } render(props, context) { const notes = this.props.notes; const style = { margin: '0.5em', paddingLeft: 0, listStyle: 'none' }; return <ul style={style}>{notes.map(this.renderNote)}</ul>; } https://survivejs.com/react/advanced-techniques/styling-react/
  • 22. Hasan @ DEV6 – #WEBU17 import React from 'react' import injectSheet from 'react-jss' const styles = { button: { background: props => props.color }, label: { fontWeight: 'bold' } } const Button = ({classes, children}) => ( <button className={classes.button}> <span className={classes.label}> {children} </span> </button> ) export default injectSheet(styles)(Button) https://github.com/cssinjs/jss
  • 23. Hasan @ DEV6 – #WEBU17 var Block = require('jsxstyle/Block'); var React = require('react'); var MyComponent = React.createClass({ render: function() { return <Block color="red">Hello, world!</Block>; } }); https://github.com/smyte/jsxstyle
  • 24. Hasan @ DEV6 – #WEBU17 Routing Angular has one routing model, driven by the URL @angular/router is engineered for many scenarios React has many different options, depending on your app architecture react-router, fluxxor-react-router, react-redux-router
  • 25. Hasan @ DEV6 – #WEBU17 template: ` <h1>Angular Router</h1> <nav> <a routerLink="/crisis-center" routerLinkActive="active">Crisis Center</a> <a routerLink="/heroes" routerLinkActive="active">Heroes</a> </nav> <router-outlet></router-outlet> ` const appRoutes: Routes = [ { path: 'crisis-center', component: CrisisListComponent }, { path: 'hero/:id', component: HeroDetailComponent }, { path: 'heroes', component: HeroListComponent, data: { title: 'Heroes List' } }, { path: '', redirectTo: '/heroes', pathMatch: 'full' }, { path: '**', component: PageNotFoundComponent } ];
  • 26. Hasan @ DEV6 – #WEBU17 // ./src/index.jsx import React, { Component } from 'react'; import { render } from 'react-dom'; // Import routing components import {Router, Route} from 'react-router'; class Home extends Component { render(){ return (<h1>Hi</h1>); } } render( <Router> <!--Each route is defined with Route--> <Route path="/" component={Home}/> </Router>, document.getElementById('container') ); https://scotch.io/tutorials/routing-react-apps-the-complete-guide
  • 27. Hasan @ DEV6 – #WEBU17 import React from 'react' import ReactDOM from 'react-dom' import { createStore, combineReducers } from 'redux' import { Provider } from 'react-redux' import { Router, Route, browserHistory } from 'react-router' import { syncHistoryWithStore, routerReducer } from 'react-router-redux' import reducers from '<project-path>/reducers' const store = createStore( combineReducers({ ...reducers, routing: routerReducer }) ) // Create an enhanced history that syncs navigation events with the store const history = syncHistoryWithStore(browserHistory, store) ReactDOM.render( <Provider store={store}> <Router history={history}> <Route path="/" component={App}> <Route path="foo" component={Foo}/> <Route path="bar" component={Bar}/> </Route> </Router> </Provider>, document.getElementById('mount') ) https://github.com/reactjs/react-router-redux
  • 28. Hasan @ DEV6 – #WEBU17 Testing Angular comes with extensive support for jasmine with karma and protractor React varies by project, some use Jest, others use Mocha/Chai/Enzyme
  • 29. Hasan @ DEV6 – #WEBU17 Cross-platform apps Extend cross platform experience beyond the browser Progressive Web Applications Cordova / Hybrid Applications NativeScript / React Native
  • 30. Hasan @ DEV6 – #WEBU17 Angular + React = ? react-native-renderer – Angular project in a react native app ng-redux – Use redux (popularized by React) in your Angular projects
  • 31. Hasan @ DEV6 – #WEBU17 Summary Equal, yet different:Two approaches to solving common problems all developers face. Choice between Angular and React is ultimately driven by an organization’s development philosophy.
  • 32. Hasan @ DEV6 – #WEBU17 ThankYou! Questions?