SlideShare a Scribd company logo
1 of 43
Download to read offline
ReactJS
A quick introduction to Awesomeness
Copyright © Ronny Haase, 2017
Why should I care?
● Component based
● Declarative
● Fast - Client, Server, Universal
● Simple
● Free choice of ecosystem around (can also be considered a drawback)
Frontend engineering done right
Why should I care?
Because these guys do care a lot:
Airbnb, Atlassian, eBay, Dropbox, EyeEM, Facebook, Flipboard, Google, Khan
Academy, Mozilla, Netflix, PayPal, Pinterest, Rangle.io, Salesforce, Slack, Spotify, Tilt,
Twitch, Twitter, Uber, WalMart, Yahoo, Zalando
https://github.com/facebook/react/wiki/sites-using-react
The Pillars
<Component />s
Components
“Declarative
React makes it painless to create interactive UIs. Design simple views for each state in
your application, and React will efficiently update and render just the right
components when your data changes.
Declarative views make your code more predictable and easier to debug.”
“Component-Based
Build encapsulated components that manage their own state, then compose them to
make complex UIs.
Since component logic is written in JavaScript instead of templates, you can easily pass
rich data through your app and keep state out of the DOM.”
Components
Components
Two Types:
Presentational Container
Components are simply functions!
(internally “classes” are functions in JavaScript as well)
Presentational Components
Only markup, TodoItem
<div className=”TodoItem”>
<label className=”TodoItem-Title”>{props.title}</label>
<div className=”BtnGroup”>
<button className=”Btn” onClick={props.editItem}>Edit</button>
<button className=”Btn” onClick={props.removeItem}>Remove</button>
</div>
</div>
Presentational Components
<TodoItemWrapper>
<TodoItemTitle>{props.title}</TodoItemTitle>
<ButtonGroup>
<Button onClick={props.editItem}>Edit</Button>
<Button onClick={props.removeItem}>Remove</Button>
</ButtonGroup>
<TodoItemWrapper>
Presentational Components
const TodoItem = (props) =>
<TodoItemWrapper>
<TodoItemTitle>{props.title}</TodoItemTitle>
<ButtonGroup>
<Button onClick={props.editItem}>Edit</Button>
<Button onClick={props.removeItem}>Remove</Button>
</ButtonGroup>
</TodoItemWrapper>
Components
● Build as granular, encapsulated and generic components as possible
○ Better Performance
○ Easier Debugging
○ Easier Testing
○ More readable and declarative
○ Reusable
Container Components
● Components that have state (we learn about state later)
● Handles it’s state and passes it down as props to presentational components
// Component
const NameOutput = ({ enteredName }) => <h1>Hi! My name is {enteredName}</h1>
// Container
class EnterName extends Component {
render() {
return
<div>
<input onChange={(ev) => this.setState({ name: ev.target.value })} />
<NameOutput enteredName={this.state.name}
</div>
}
}
JSX
JavaScript XML
● No requirement
● Makes React declarative
● It’s XML (like HTML is) with full JavaScript power (you could do anything
within curly braces)
Elements
Elements are instances of Components
Lifecycle Methods
Hooks on certain state changes:
(Constructor), Mount, Unmount, Should Update?, Will Update, etc.
Explicit
Uni-Directional Data Flow
Data Types
The Two Data Types in React Applications
In React there are only two types of data:
● State
● Props
Props
● Read-only (!)
● Passed from the top
● Can be passed on down
○ Prefer specific or no passing down
○ Only pass on all props when necessary
● Are a reflection of your component tree
○ You only get relevant data
○ And only pass on the data relevant for your children
State
● If a component requires data that can change, or needs to store data you put them
into its State
● Immutable, plain Objects
● Pass on down as props
● Eventually Props can be the source (do not assign by reference!)
this.state = this.props.whatever
this.state = { ...this.props.whatever }
Data Flow
Looks familiar?
Yep, It’s a mess!
Your backend already did the MVC part, why repeat it on front-end?!
Just take the data and put them into your view!
Action = Click, request, new data
Dispatcher = Container Component, or e.g. Redux Dispatcher
Store = Container State, or e.g. Redux Store
View = Presentational Components
FLUX
React is the V in MVCReact is the V in MVC
VDOM
The Browser DOM is slow.
VDOM
● React keeps it’s own DOM (subtree) representation(s) and a copy of the actual
DOM in memory
● On Change (Props or State)
○ It diffs the DOMs in memory (fast!)
○ Parses tree and only rerenders elements where necessary in memory (faster!)
○ Mutates DOM all at once (even faster!)
Only one DOM mutation instead of multiple, each may requiring a browser repaint
○ Reconciliation
Does this concept sound familiar?
Bonuses
Flawless Server-Side & Universal Rendering
Even faster!
Client-side (SPA)
import { render } from ‘react-dom’;
const el = document.getElementById(‘mount’);
render(<MyComponent />, el);
Server-side
import { renderToString as render } from ‘react-dom/server’;
render(<MyComponent />);
Universal
import { renderToString as render } from ‘react-dom/server’;
return `
<div id=”mount”>
${render(<MyComponent />)}
</div>
`;
If you call the code from 2 slides before on client-side now, React will recognize the server-side rendered
component and only attach the missing parts powered by VDOM (very, very, very performant!)
Links
● Hacker Way: Rethinking Web App Development at Facebook
Official React announcement
● Learning Functional Programming with JavaScript by Anjana Vakil
Very basic but great introduction to Functional Programming
● Functional Programming Series by Eric Elliott
Great for diving deeper into Functional Programming
● How we built Twitter Lite
Great example for a light, mobile-first, progressive web app, built with React
Questions?
Let’s do some coding!
API
https://nodod-rsmmjhqasm.now.sh/todos
GET / - Get list of all tasks
POST / - Create task
GET /:id - Get specific task
PUT /:id - Update specific task
DELETE /:id - Delete specific task
Schema:
TodoItem { “title”: “Task title”, “completed”: false,
“created_at”: “1498566756549”, “updated_at”: “1498566794201” }
Run your own: https://github.com/ronnyhaase/nodod

More Related Content

What's hot

React & Redux JS
React & Redux JS React & Redux JS
React & Redux JS Hamed Farag
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux jsCitrix
 
Building React Applications with Redux
Building React Applications with ReduxBuilding React Applications with Redux
Building React Applications with ReduxFITC
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JSArno Lordkronos
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorialMohammed Fazuluddin
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React NativeEric Deng
 
The Benefits of Using React JS for Web Development!
The Benefits of Using React JS for Web Development!The Benefits of Using React JS for Web Development!
The Benefits of Using React JS for Web Development!Baharika Sopori
 
Academy PRO: React JS
Academy PRO: React JSAcademy PRO: React JS
Academy PRO: React JSBinary Studio
 
Introduction to React by Ebowe Blessing
Introduction to React by Ebowe BlessingIntroduction to React by Ebowe Blessing
Introduction to React by Ebowe BlessingBlessing Ebowe
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥Remo Jansen
 
Understanding Facebook's React.js
Understanding Facebook's React.jsUnderstanding Facebook's React.js
Understanding Facebook's React.jsFederico Torre
 
Robust web apps with React.js
Robust web apps with React.jsRobust web apps with React.js
Robust web apps with React.jsMax Klymyshyn
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJSKnoldus Inc.
 

What's hot (20)

Intro to React
Intro to ReactIntro to React
Intro to React
 
React & Redux JS
React & Redux JS React & Redux JS
React & Redux JS
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
 
Building React Applications with Redux
Building React Applications with ReduxBuilding React Applications with Redux
Building React Applications with Redux
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
React and redux
React and reduxReact and redux
React and redux
 
How to Redux
How to ReduxHow to Redux
How to Redux
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
 
The Benefits of Using React JS for Web Development!
The Benefits of Using React JS for Web Development!The Benefits of Using React JS for Web Development!
The Benefits of Using React JS for Web Development!
 
Academy PRO: React JS
Academy PRO: React JSAcademy PRO: React JS
Academy PRO: React JS
 
Introduction to React by Ebowe Blessing
Introduction to React by Ebowe BlessingIntroduction to React by Ebowe Blessing
Introduction to React by Ebowe Blessing
 
Let's Redux!
Let's Redux!Let's Redux!
Let's Redux!
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
Understanding Facebook's React.js
Understanding Facebook's React.jsUnderstanding Facebook's React.js
Understanding Facebook's React.js
 
React redux
React reduxReact redux
React redux
 
Robust web apps with React.js
Robust web apps with React.jsRobust web apps with React.js
Robust web apps with React.js
 
React&redux
React&reduxReact&redux
React&redux
 
Redux workshop
Redux workshopRedux workshop
Redux workshop
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 

Similar to ReactJS - A quick introduction to Awesomeness

React JS and Redux
React JS and ReduxReact JS and Redux
React JS and ReduxGlib Kechyn
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today Nitin Tyagi
 
Content-Driven Apps with React
Content-Driven Apps with ReactContent-Driven Apps with React
Content-Driven Apps with ReactNetcetera
 
Introduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptxIntroduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptxSHAIKIRFAN715544
 
Getting started with React and Redux
Getting started with React and ReduxGetting started with React and Redux
Getting started with React and ReduxPaddy Lock
 
Introduction to React JS.pptx
Introduction to React JS.pptxIntroduction to React JS.pptx
Introduction to React JS.pptxSHAIKIRFAN715544
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react jsStephieJohn
 
Combining Angular and React Together
Combining Angular and React TogetherCombining Angular and React Together
Combining Angular and React TogetherSebastian Pederiva
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]GDSC UofT Mississauga
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core ConceptsDivyang Bhambhani
 
Using React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsUsing React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsMihail Gaberov
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Previewvaluebound
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Marco Breveglieri
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)Chiew Carol
 

Similar to ReactJS - A quick introduction to Awesomeness (20)

ReactJS
ReactJSReactJS
ReactJS
 
React JS and Redux
React JS and ReduxReact JS and Redux
React JS and Redux
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
 
Content-Driven Apps with React
Content-Driven Apps with ReactContent-Driven Apps with React
Content-Driven Apps with React
 
Introduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptxIntroduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptx
 
Getting started with React and Redux
Getting started with React and ReduxGetting started with React and Redux
Getting started with React and Redux
 
ReactJS.ppt
ReactJS.pptReactJS.ppt
ReactJS.ppt
 
Introduction to React JS.pptx
Introduction to React JS.pptxIntroduction to React JS.pptx
Introduction to React JS.pptx
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
React/Redux
React/ReduxReact/Redux
React/Redux
 
Combining Angular and React Together
Combining Angular and React TogetherCombining Angular and React Together
Combining Angular and React Together
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core Concepts
 
React native
React nativeReact native
React native
 
Using React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsUsing React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIs
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016Web Development with Delphi and React - ITDevCon 2016
Web Development with Delphi and React - ITDevCon 2016
 
SharePoint Framework y React
SharePoint Framework y ReactSharePoint Framework y React
SharePoint Framework y React
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
 
React & Redux
React & ReduxReact & Redux
React & Redux
 

Recently uploaded

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 

Recently uploaded (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 

ReactJS - A quick introduction to Awesomeness

  • 1. ReactJS A quick introduction to Awesomeness Copyright © Ronny Haase, 2017
  • 2. Why should I care? ● Component based ● Declarative ● Fast - Client, Server, Universal ● Simple ● Free choice of ecosystem around (can also be considered a drawback) Frontend engineering done right
  • 3. Why should I care? Because these guys do care a lot: Airbnb, Atlassian, eBay, Dropbox, EyeEM, Facebook, Flipboard, Google, Khan Academy, Mozilla, Netflix, PayPal, Pinterest, Rangle.io, Salesforce, Slack, Spotify, Tilt, Twitch, Twitter, Uber, WalMart, Yahoo, Zalando https://github.com/facebook/react/wiki/sites-using-react
  • 6. Components “Declarative React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes. Declarative views make your code more predictable and easier to debug.”
  • 7. “Component-Based Build encapsulated components that manage their own state, then compose them to make complex UIs. Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep state out of the DOM.” Components
  • 8. Components Two Types: Presentational Container Components are simply functions! (internally “classes” are functions in JavaScript as well)
  • 9. Presentational Components Only markup, TodoItem <div className=”TodoItem”> <label className=”TodoItem-Title”>{props.title}</label> <div className=”BtnGroup”> <button className=”Btn” onClick={props.editItem}>Edit</button> <button className=”Btn” onClick={props.removeItem}>Remove</button> </div> </div>
  • 11. Presentational Components const TodoItem = (props) => <TodoItemWrapper> <TodoItemTitle>{props.title}</TodoItemTitle> <ButtonGroup> <Button onClick={props.editItem}>Edit</Button> <Button onClick={props.removeItem}>Remove</Button> </ButtonGroup> </TodoItemWrapper>
  • 12. Components ● Build as granular, encapsulated and generic components as possible ○ Better Performance ○ Easier Debugging ○ Easier Testing ○ More readable and declarative ○ Reusable
  • 13. Container Components ● Components that have state (we learn about state later) ● Handles it’s state and passes it down as props to presentational components // Component const NameOutput = ({ enteredName }) => <h1>Hi! My name is {enteredName}</h1> // Container class EnterName extends Component { render() { return <div> <input onChange={(ev) => this.setState({ name: ev.target.value })} /> <NameOutput enteredName={this.state.name} </div> } }
  • 14. JSX JavaScript XML ● No requirement ● Makes React declarative ● It’s XML (like HTML is) with full JavaScript power (you could do anything within curly braces)
  • 16. Lifecycle Methods Hooks on certain state changes: (Constructor), Mount, Unmount, Should Update?, Will Update, etc.
  • 19. The Two Data Types in React Applications In React there are only two types of data: ● State ● Props
  • 20. Props ● Read-only (!) ● Passed from the top ● Can be passed on down ○ Prefer specific or no passing down ○ Only pass on all props when necessary ● Are a reflection of your component tree ○ You only get relevant data ○ And only pass on the data relevant for your children
  • 21. State ● If a component requires data that can change, or needs to store data you put them into its State ● Immutable, plain Objects ● Pass on down as props ● Eventually Props can be the source (do not assign by reference!) this.state = this.props.whatever this.state = { ...this.props.whatever }
  • 23.
  • 24. Looks familiar? Yep, It’s a mess! Your backend already did the MVC part, why repeat it on front-end?! Just take the data and put them into your view!
  • 25. Action = Click, request, new data Dispatcher = Container Component, or e.g. Redux Dispatcher Store = Container State, or e.g. Redux Store View = Presentational Components
  • 26. FLUX
  • 27. React is the V in MVCReact is the V in MVC
  • 28. VDOM
  • 29. The Browser DOM is slow.
  • 30. VDOM ● React keeps it’s own DOM (subtree) representation(s) and a copy of the actual DOM in memory ● On Change (Props or State) ○ It diffs the DOMs in memory (fast!) ○ Parses tree and only rerenders elements where necessary in memory (faster!) ○ Mutates DOM all at once (even faster!) Only one DOM mutation instead of multiple, each may requiring a browser repaint ○ Reconciliation
  • 31. Does this concept sound familiar?
  • 32.
  • 33.
  • 34.
  • 36. Flawless Server-Side & Universal Rendering Even faster!
  • 37. Client-side (SPA) import { render } from ‘react-dom’; const el = document.getElementById(‘mount’); render(<MyComponent />, el);
  • 38. Server-side import { renderToString as render } from ‘react-dom/server’; render(<MyComponent />);
  • 39. Universal import { renderToString as render } from ‘react-dom/server’; return ` <div id=”mount”> ${render(<MyComponent />)} </div> `; If you call the code from 2 slides before on client-side now, React will recognize the server-side rendered component and only attach the missing parts powered by VDOM (very, very, very performant!)
  • 40. Links ● Hacker Way: Rethinking Web App Development at Facebook Official React announcement ● Learning Functional Programming with JavaScript by Anjana Vakil Very basic but great introduction to Functional Programming ● Functional Programming Series by Eric Elliott Great for diving deeper into Functional Programming ● How we built Twitter Lite Great example for a light, mobile-first, progressive web app, built with React
  • 42. Let’s do some coding!
  • 43. API https://nodod-rsmmjhqasm.now.sh/todos GET / - Get list of all tasks POST / - Create task GET /:id - Get specific task PUT /:id - Update specific task DELETE /:id - Delete specific task Schema: TodoItem { “title”: “Task title”, “completed”: false, “created_at”: “1498566756549”, “updated_at”: “1498566794201” } Run your own: https://github.com/ronnyhaase/nodod