SlideShare una empresa de Scribd logo
1 de 15
Introduction to React
& MobX
Anjali Chawla
SDE-II Expedia
Agenda
 What is React
 How React works
 React Component lifecycle
 State management - MobX
What is React
 A JavaScript library for building user interfaces
Declarative
 Create interactive Uis
 Design simple views
 Predictable and easier
to debug code
Component Based
 Building block of
complex UI
 Manage their own
state
Learn Once, write
anywhere
 Create Web based
applications
 Progressive WebApps
 Native Mobile Apps
How does React Work
HTML
JS
How Browsers work
Add CSS
DOM Tree
Parser
Render Tree
Painted
Browser
How React works
HTML
JS
Host Tree/
Virtual DOM
Parser
React maps the DOM tree and the Host tree
to allow for minimal updates in the browser
Host Tree
Host Element
document.createElement(div)
<div>...</div>
<footer>
</footer>
<article></article>
Properties: classname
<footer></footer>
Renderer
Dom Renderer React Native
React Element
{ type: 'dialog’,
props: {
children: [{ type: 'button', props: { className: 'blue' } },
{ type: 'button', props: { className: 'red' } }]
} }
Entry Point:
ReactDOM.render( // { type: 'button', props: { className: 'blue' } }
<button className="blue" />,
document.getElementById('container’)
);
Components
function Button (props) {
// Returns a DOM element here. For example:
return <button type="submit">{props.label}</button>;
}
ReactDOM.render(<Button label="Save" />, mountNode)
const InputForm = React.createElement(
"form",
{ target: "_blank", action: "https://google.com/search" },
React.createElement("div", null, "Enter input and click Search"),
React.createElement("input", { name: "q", className: "input" }),
React.createElement(Button, { label: "Search" })
);
Pure Components /
Functional Components /
Stateless Components
const InputForm =
<form target="_blank" action="https://google.com/search">
<div>Enter input and click Search</div>
<input name="q" className="input" />
<Button label="Search" />
</form>;
Creating component using
JSX -
Javascript Expressions
Creating
component using
React API
Components
class CounterButton extends React.Component {
state = {
clickCounter: 0,
currentTimestamp: new Date(),
};
handleClick = () => { this.setState((prevState) => {
return { clickCounter: prevState.clickCounter + 1 };});
};
render() {
return (
<div>
<button onClick={this.handleClick}>Click</button>
<p>Clicked: {this.state.clickCounter}</p>
<p>Time: {this.state.currentTimestamp.toLocaleString()}</p>
</div>);}
}// Use it
ReactDOM.render(<CounterButton />, mountNode);
Stateful Components /
Class Components
Components Data Dependency
class CounterButton extends React.Component {
onHandleClick() { // handle onclick event
}
render() {
return (
<div>
<Button onHandleClick={this.onHandleClick} />
</div>);}
}
ReactDOM.render(<CounterButton />, mountNode);
class Button extends React.Component {
render(){
return <button onClick={this.props.onHandleClick}> Click </button>
}
}
Parent Component
Child Component 1a
Child Component 1
Props
Props
State
State
Component Life Cycle
MobX - State Management
 MobX provides mechanisms to optimally synchronize application state with
the React components by using a reactive virtual dependency state graph that
is only updated when strictly needed and is never stale.
MobX
MobX - Core Concepts
 Observable state
 Computed values
import { observable } from "mobx";
class Todo {
id = Math.random();
@observable title = "";
@observable finished = false; }
class TodoList {
@observable todos = [];
@computed get unfinishedTodoCount() {
return this.todos.filter(todo => !todo.finished).length;
}
}
MobX – Core Concepts
 Reactions
 Actions
@observer
class TodoListView extends Component {
render() {
return ( <div> <ul>
{this.props.todoList.todos.map(todo => ( <TodoView todo={todo} key={todo.id} />
))} </ul>
Tasks left: {this.props.todoList.unfinishedTodoCount}
</div> ); } }
store.todos.push(new Todo("Get Coffee"), new Todo("Write simpler code"));
store.todos[0].finished = true;
References
 https://reactjs.org/
 https://overreacted.io/react-as-a-ui-runtime/
 https://medium.freecodecamp.org/all-the-fundamental-react-js-concepts-
jammed-into-this-single-medium-article-c83f9b53eac2
 https://mobx.js.org/
 https://medium.com/@mweststrate/mobx-4-better-simpler-faster-smaller-
c1fbc08008da
 https://hackernoon.com/becoming-fully-reactive-an-in-depth-explanation-of-
mobservable-55995262a254

Más contenido relacionado

La actualidad más candente

J Query(04 12 2008) Foiaz
J Query(04 12 2008) FoiazJ Query(04 12 2008) Foiaz
J Query(04 12 2008) Foiaz
testingphase
 
Introduction to j query
Introduction to j queryIntroduction to j query
Introduction to j query
thewarlog
 
Binding components, events + data sources in HTML + JS
Binding components, events + data sources in HTML + JSBinding components, events + data sources in HTML + JS
Binding components, events + data sources in HTML + JS
Vladimir Dzhuvinov
 

La actualidad más candente (20)

Introduction to react and redux
Introduction to react and reduxIntroduction to react and redux
Introduction to react and redux
 
J Query(04 12 2008) Foiaz
J Query(04 12 2008) FoiazJ Query(04 12 2008) Foiaz
J Query(04 12 2008) Foiaz
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & Angular
 
Jquery beltranhomewrok
Jquery beltranhomewrokJquery beltranhomewrok
Jquery beltranhomewrok
 
Web Components: The future of Web Application Development
Web Components: The future of Web Application DevelopmentWeb Components: The future of Web Application Development
Web Components: The future of Web Application Development
 
Knockout.js
Knockout.jsKnockout.js
Knockout.js
 
Jquery Basics
Jquery BasicsJquery Basics
Jquery Basics
 
J query resh
J query reshJ query resh
J query resh
 
Javascript dom event
Javascript dom eventJavascript dom event
Javascript dom event
 
Unobtrusive JavaScript
Unobtrusive JavaScriptUnobtrusive JavaScript
Unobtrusive JavaScript
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
 
Devoxx 2014-webComponents
Devoxx 2014-webComponentsDevoxx 2014-webComponents
Devoxx 2014-webComponents
 
Javascipt
JavasciptJavascipt
Javascipt
 
Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developer
 
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
 
Introduction to j query
Introduction to j queryIntroduction to j query
Introduction to j query
 
Web Development Introduction to jQuery
Web Development Introduction to jQueryWeb Development Introduction to jQuery
Web Development Introduction to jQuery
 
Binding components, events + data sources in HTML + JS
Binding components, events + data sources in HTML + JSBinding components, events + data sources in HTML + JS
Binding components, events + data sources in HTML + JS
 
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham SiddiquiJ Query (Complete Course) by Muhammad Ehtisham Siddiqui
J Query (Complete Course) by Muhammad Ehtisham Siddiqui
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 

Similar a Introduction to React and MobX

Similar a Introduction to React and MobX (20)

Server side rendering with React and Symfony
Server side rendering with React and SymfonyServer side rendering with React and Symfony
Server side rendering with React and Symfony
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
 
React outbox
React outboxReact outbox
React outbox
 
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
 
Introduction to React for Frontend Developers
Introduction to React for Frontend DevelopersIntroduction to React for Frontend Developers
Introduction to React for Frontend Developers
 
Let's react - Meetup
Let's react - MeetupLet's react - Meetup
Let's react - Meetup
 
React.js workshop by tech47.in
React.js workshop by tech47.inReact.js workshop by tech47.in
React.js workshop by tech47.in
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
ReactJS
ReactJSReactJS
ReactJS
 
Manage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxManage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's Redux
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
 
Creating a WYSIWYG Editor with React
Creating a WYSIWYG Editor with ReactCreating a WYSIWYG Editor with React
Creating a WYSIWYG Editor with React
 
React JS - Introduction
React JS - IntroductionReact JS - Introduction
React JS - Introduction
 
Academy PRO: React JS
Academy PRO: React JSAcademy PRO: React JS
Academy PRO: React JS
 
A full introductory guide to React
A full introductory guide to ReactA full introductory guide to React
A full introductory guide to React
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017
 
React js
React jsReact js
React js
 
Intro react js
Intro react jsIntro react js
Intro react js
 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Native
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 

Introduction to React and MobX

  • 1. Introduction to React & MobX Anjali Chawla SDE-II Expedia
  • 2. Agenda  What is React  How React works  React Component lifecycle  State management - MobX
  • 3. What is React  A JavaScript library for building user interfaces Declarative  Create interactive Uis  Design simple views  Predictable and easier to debug code Component Based  Building block of complex UI  Manage their own state Learn Once, write anywhere  Create Web based applications  Progressive WebApps  Native Mobile Apps
  • 4. How does React Work HTML JS How Browsers work Add CSS DOM Tree Parser Render Tree Painted Browser How React works HTML JS Host Tree/ Virtual DOM Parser React maps the DOM tree and the Host tree to allow for minimal updates in the browser
  • 6. React Element { type: 'dialog’, props: { children: [{ type: 'button', props: { className: 'blue' } }, { type: 'button', props: { className: 'red' } }] } } Entry Point: ReactDOM.render( // { type: 'button', props: { className: 'blue' } } <button className="blue" />, document.getElementById('container’) );
  • 7. Components function Button (props) { // Returns a DOM element here. For example: return <button type="submit">{props.label}</button>; } ReactDOM.render(<Button label="Save" />, mountNode) const InputForm = React.createElement( "form", { target: "_blank", action: "https://google.com/search" }, React.createElement("div", null, "Enter input and click Search"), React.createElement("input", { name: "q", className: "input" }), React.createElement(Button, { label: "Search" }) ); Pure Components / Functional Components / Stateless Components const InputForm = <form target="_blank" action="https://google.com/search"> <div>Enter input and click Search</div> <input name="q" className="input" /> <Button label="Search" /> </form>; Creating component using JSX - Javascript Expressions Creating component using React API
  • 8. Components class CounterButton extends React.Component { state = { clickCounter: 0, currentTimestamp: new Date(), }; handleClick = () => { this.setState((prevState) => { return { clickCounter: prevState.clickCounter + 1 };}); }; render() { return ( <div> <button onClick={this.handleClick}>Click</button> <p>Clicked: {this.state.clickCounter}</p> <p>Time: {this.state.currentTimestamp.toLocaleString()}</p> </div>);} }// Use it ReactDOM.render(<CounterButton />, mountNode); Stateful Components / Class Components
  • 9. Components Data Dependency class CounterButton extends React.Component { onHandleClick() { // handle onclick event } render() { return ( <div> <Button onHandleClick={this.onHandleClick} /> </div>);} } ReactDOM.render(<CounterButton />, mountNode); class Button extends React.Component { render(){ return <button onClick={this.props.onHandleClick}> Click </button> } } Parent Component Child Component 1a Child Component 1 Props Props State State
  • 11. MobX - State Management  MobX provides mechanisms to optimally synchronize application state with the React components by using a reactive virtual dependency state graph that is only updated when strictly needed and is never stale.
  • 12. MobX
  • 13. MobX - Core Concepts  Observable state  Computed values import { observable } from "mobx"; class Todo { id = Math.random(); @observable title = ""; @observable finished = false; } class TodoList { @observable todos = []; @computed get unfinishedTodoCount() { return this.todos.filter(todo => !todo.finished).length; } }
  • 14. MobX – Core Concepts  Reactions  Actions @observer class TodoListView extends Component { render() { return ( <div> <ul> {this.props.todoList.todos.map(todo => ( <TodoView todo={todo} key={todo.id} /> ))} </ul> Tasks left: {this.props.todoList.unfinishedTodoCount} </div> ); } } store.todos.push(new Todo("Get Coffee"), new Todo("Write simpler code")); store.todos[0].finished = true;
  • 15. References  https://reactjs.org/  https://overreacted.io/react-as-a-ui-runtime/  https://medium.freecodecamp.org/all-the-fundamental-react-js-concepts- jammed-into-this-single-medium-article-c83f9b53eac2  https://mobx.js.org/  https://medium.com/@mweststrate/mobx-4-better-simpler-faster-smaller- c1fbc08008da  https://hackernoon.com/becoming-fully-reactive-an-in-depth-explanation-of- mobservable-55995262a254