SlideShare une entreprise Scribd logo
1  sur  33
React JS: A Secret Preview
Prashant Sharma
https://www.linkedin.com/in/response2prashant
Agendas
1. Introduction
2. What is React JS?
3. What is Single Page Application?
4. Why React is better than other SPA?
5. React JS Setup
6. React JSX
7. ES6 Arrow Function
8. React Components
9. Component Life Cycle
10. Error Boundaries
11. React Higher Order Component (hoc)
12. Axios in React
to be continued….
12. Redux
13. Advantages of React JS
14. Disadvantages of React JS
● React is a front-end library developed by Facebook, in the year 2013.
● It is used for handling the view layer for web and mobile apps.
● ReactJS allows us to create reusable UI components.
● It is currently one of the most popular JavaScript libraries and has a
strong foundation and large community behind it.
Introduction
● React is a library for building composable user interfaces.
● It encourages the creation of reusable UI components, which present
data that changes over time.
● React abstracts away the DOM from you, offering a simpler
programming model and better performance.
● React can also render on the server using Node, and it can power
native apps using React Native.
● React implements one-way reactive data flow, which reduces the
boilerplate and is easier to reason about than traditional data binding.
What is React JS ?
What is Single Page Applications?
A single-page application is an app that works inside a browser and does
not require page reloading during use.
You are using this type of applications every day. These are for instance:
Gmail, Google Maps, Facebook and GitHub.
● There are various Single Page Applications Frameworks like Angularjs,
Reactjs and Vuejs.
● Angularjs is a MVC framework . Angularjs is complicated in comparison
to Reactjs and Vuejs but proper documentation available.
● Reactjs is a library not a framework and easy to learn but proper
documentation is not available.
Why React is better than other
SPAs?
...to be continue
● High level of flexibility and maximum of responsiveness.
● Vue js describes itself as “The Progressive JavaScript Frameworks”
and easy to learn in comparison to Angularjs and Reactjs.
● Lack of full english documentation.
● Vue js might have issues while integrating into huge projects.
Step: 1
Install node in your system
Step: 2
Open terminal type npm init react-app my-app
Step: 3
type cd my-app
Step: 4
type npm start
Step: 5
Now you can start building react app.
React configuration
React JSX
React uses JSX for templating instead of regular JavaScript. It is not
necessary to use it, however, following are some pros that come with it.
1. It is faster because it performs optimization while compiling code to
JavaScript.
2. It is also type-safe and most of the errors can be caught during
compilation.
3. It makes it easier and faster to write templates, if you are familiar with
HTML.
...to be continued
import React, {Component} from 'react';
import Layout from './components/Layout/Layout.js';
import BurgerBuilder from './containers/BurgerBuilder/BurgerBuilder';
import { BrowserRouter, Route, link} from 'react-router-dom';
class App extends Component {
render() {
return (
<div>
<BrowserRouter>
<Layout>
<Route path="/" exact component={BurgerBuilder} />
</Layout>
</BrowserRouter>
</div>
);
}
}
export default App;
ES6 Arrow Function
arrowfunctionExample = () => {
return(
<div>Something</div>
);
}
Arrow function single parameter syntax:
arrowfunctionExample = a => a*a;
Arrow function double parameter syntax:
arrowfunctionExample = (a,b) => a*b;
Arrow function with JSX:
arrowfunctionExample = () => (<div>Something</div>);
….to be continued
Arrow function with multiple line:
arrowfunctionExample = (a, b) =>{
const c = a+b;
return (
<div>Something {c}</div>
);
}
React Components
There are basically two types of component are used:
1. Stateful component
2. Stateless component
...to be continued
Stateful components:
import Backdrop from ‘backdrop’;
class Person extends Component {
state={
count: 0
}
render(){
return(
<div>
{this.state.count
<Backdrop show=”true” />
</div>);
}
}
export default Person:
...to be continued
Stateless components:
Stateless components have not their own state always dependant upon
another component. These components are reusable components.
const backdrop = (props) => (
props.show
?<div className={classes.Backdrop} onClick={props.clicked}></div>
: null
);
React Component Lifecycle
● We need more control over the stages that a component goes
through.
● The process where all these stages are involved is called the
component’s lifecycle and every React component goes through it.
● React provides several methods that notify us when certain stage of
this process occurs.
● These methods are called the component’s lifecycle methods and
they are invoked in a predictable order.
...to be continued
Basically all the React component’s lifecyle methods can be split in four
phases: initialization, mounting, updating and unmounting. Let’s take a
closer look at each one of them.
Initialization
The initialization phase is where we define defaults and initial values for
this.props and this.state by implementing getDefaultProps() and
getInitialState() respectively.
...to be continued
Mounting
Mounting is the process that occurs when a component is being inserted
into the DOM. This phase has two methods that we can hook up with:
componentWillMount() and componentDidMount().
componentWillMount() method is first called in this phase.
componentDidMount() is invoked second in this phase.
...to be continued
Updating
There are also methods that will allow us to execute code relative to when
a component’s state or properties get updated. These methods are part of
the updating phase and are called in the following order:
componentWillReceiveProps()
shouldComponentUpdate()
componentWillUpdate()
render()
componentDidUpdate()
When received new
props from the parent.
...to be continued
Unmounting
In this phase React provide us with only one method:
● componentWillUnmount()
It is called immediately before the component is unmounted
from the DOM.
Error Boundaries
● A JavaScript error in a part of the UI shouldn’t break the whole app.
● To solve this problem for React users, React 16 introduces a new
concept of an “error boundary”.
● Error boundaries are React components that catch JavaScript errors
anywhere in their child component tree, log those errors, and display a
fallback UI instead of the component tree that crashed.
● Error boundaries catch errors during rendering, in lifecycle methods,
and in constructors of the whole tree below them.
...to be continued
class ErroBoundary extends React.Component{
state= {
hasError: false
}
componentDidCatch(error, info){
//Display fallback, UI
this,setState({hasError:true});
// You can also log error to an error reporting service
logErrorToMyService(error, info);
}
render(){
if(this.state.hasError){
return (<div>Something went wrong</div>);
}
return this.props.children;
}
}
...to be continued
Then you can use it as a regular component
<ErrorBoundary>
<MyComponent />
</ErrorBoundary>
React Higher Order Component
● A higher-order component in React is a pattern used to share common
functionality between components without repeating code.
● A higher-order component is actually not a component though, it is a
function.
● A HOC function takes a component as an argument and returns a
component.
● It transforms a component into another component and adds
additional data or functionality.
...to be continued
const NewComponent = (BaseComponent) => {
// ... create new component from old one and update
return UpdatedComponent
}
Axios in React
● Every project needs to interact with a REST API at some stage.
● Axios provides interaction with REST API.
● With the help of AXIOS you can send GET, POST, PUT and DELETE
request to the REST API and render response to our app.
● Axios is promise based.
What is Redux?
Redux is a predictable state container for JavaScript apps. Redux
uses this concept of uni-directional data flow:
● The application has a central /root state.
● A state change triggers View updates.
● Only special functions can change the state.
● A user interaction triggers these special, state changing functions.
● Only one change takes place at a time.
...to be continued
Advantages of React JS
1. Virtual DOM in ReactJS makes user experience better and
developer’s work faster.
2. Permission to reuse React components significantly saves time.
3. One-direction data flow in ReactJS provides a stable code.
4. An open-source library: constantly developing and open to
contributions.
Disadvantages of React
1. High pace of development.
2. Poor documentation.
3. ‘HTML in my JavaScript!’ – JSX as a barrier.
Thank you

Contenu connexe

Tendances

[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
洪 鹏发
 

Tendances (20)

Reactjs
Reactjs Reactjs
Reactjs
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
ReactJs
ReactJsReactJs
ReactJs
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
 
ReactJS
ReactJSReactJS
ReactJS
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
Introduction to react js
Introduction to react jsIntroduction to react js
Introduction to react js
 
React JS - Introduction
React JS - IntroductionReact JS - Introduction
React JS - Introduction
 
React state
React  stateReact  state
React state
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
 
React workshop presentation
React workshop presentationReact workshop presentation
React workshop presentation
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace IT
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
React js
React jsReact js
React js
 
React Class Components vs Functional Components: Which is Better?
React Class Components vs Functional Components: Which is Better?React Class Components vs Functional Components: Which is Better?
React Class Components vs Functional Components: Which is Better?
 
What is component in reactjs
What is component in reactjsWhat is component in reactjs
What is component in reactjs
 

Similaire à React JS: A Secret Preview

Welcome to React & Flux !
Welcome to React & Flux !Welcome to React & Flux !
Welcome to React & Flux !
Ritesh Kumar
 
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
SHAIKIRFAN715544
 

Similaire à React JS: A Secret Preview (20)

Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
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]
 
Intro react js
Intro react jsIntro react js
Intro react js
 
Tech Talk on ReactJS
Tech Talk on ReactJSTech Talk on ReactJS
Tech Talk on ReactJS
 
class based component.pptx
class based component.pptxclass based component.pptx
class based component.pptx
 
What are the components in React?
What are the components in React?What are the components in React?
What are the components in React?
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
 
React gsg presentation with ryan jung &amp; elias malik
React   gsg presentation with ryan jung &amp; elias malikReact   gsg presentation with ryan jung &amp; elias malik
React gsg presentation with ryan jung &amp; elias malik
 
Presentation1
Presentation1Presentation1
Presentation1
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdf
 
Welcome to React & Flux !
Welcome to React & Flux !Welcome to React & Flux !
Welcome to React & Flux !
 
React Basic and Advance || React Basic
React Basic and Advance   || React BasicReact Basic and Advance   || React Basic
React Basic and Advance || React Basic
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAs
 
React JS Interview Question & Answer
React JS Interview Question & AnswerReact JS Interview Question & Answer
React JS Interview Question & Answer
 
React JS .NET
React JS .NETReact JS .NET
React JS .NET
 
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
 
FRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JSFRONTEND DEVELOPMENT WITH REACT.JS
FRONTEND DEVELOPMENT WITH REACT.JS
 
Copy of React_JS_Notes.pdf
Copy of React_JS_Notes.pdfCopy of React_JS_Notes.pdf
Copy of React_JS_Notes.pdf
 
Introduction to React JS.pptx
Introduction to React JS.pptxIntroduction to React JS.pptx
Introduction to React JS.pptx
 
Build web apps with react js
Build web apps with react jsBuild web apps with react js
Build web apps with react js
 

Plus de valuebound

How to Use DDEV to Streamline Your Drupal Development Process.
How to Use DDEV to Streamline Your Drupal Development Process.How to Use DDEV to Streamline Your Drupal Development Process.
How to Use DDEV to Streamline Your Drupal Development Process.
valuebound
 
How to Use AWS to Automate Your IT Operation| Valuebound
How to Use AWS to Automate Your IT Operation| Valuebound How to Use AWS to Automate Your IT Operation| Valuebound
How to Use AWS to Automate Your IT Operation| Valuebound
valuebound
 
The Benefits of Cloud Engineering
The Benefits of Cloud EngineeringThe Benefits of Cloud Engineering
The Benefits of Cloud Engineering
valuebound
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computing
valuebound
 
The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...
The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...
The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...
valuebound
 

Plus de valuebound (20)

Scaling Drupal for High Traffic Websites
Scaling Drupal for High Traffic WebsitesScaling Drupal for High Traffic Websites
Scaling Drupal for High Traffic Websites
 
Drupal 7 to Drupal 10 Migration A Fintech Strategic Blueprint (1).pdf
Drupal 7 to Drupal 10 Migration A Fintech Strategic Blueprint (1).pdfDrupal 7 to Drupal 10 Migration A Fintech Strategic Blueprint (1).pdf
Drupal 7 to Drupal 10 Migration A Fintech Strategic Blueprint (1).pdf
 
How to Use DDEV to Streamline Your Drupal Development Process.
How to Use DDEV to Streamline Your Drupal Development Process.How to Use DDEV to Streamline Your Drupal Development Process.
How to Use DDEV to Streamline Your Drupal Development Process.
 
How to Use AWS to Automate Your IT Operation| Valuebound
How to Use AWS to Automate Your IT Operation| Valuebound How to Use AWS to Automate Your IT Operation| Valuebound
How to Use AWS to Automate Your IT Operation| Valuebound
 
How to Use Firebase to Send Push Notifications to React Native and Node.js Apps
How to Use Firebase to Send Push Notifications to React Native and Node.js AppsHow to Use Firebase to Send Push Notifications to React Native and Node.js Apps
How to Use Firebase to Send Push Notifications to React Native and Node.js Apps
 
Mastering Drupal Theming
Mastering Drupal ThemingMastering Drupal Theming
Mastering Drupal Theming
 
The Benefits of Cloud Engineering
The Benefits of Cloud EngineeringThe Benefits of Cloud Engineering
The Benefits of Cloud Engineering
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computing
 
The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...
The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...
The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...
 
Deep dive into ChatGPT
Deep dive into ChatGPTDeep dive into ChatGPT
Deep dive into ChatGPT
 
Content Creation Solution | Valuebound
Content Creation Solution | ValueboundContent Creation Solution | Valuebound
Content Creation Solution | Valuebound
 
Road ahead for Drupal 8 contributed projects
Road ahead for Drupal 8 contributed projectsRoad ahead for Drupal 8 contributed projects
Road ahead for Drupal 8 contributed projects
 
Chatbot with RASA | Valuebound
Chatbot with RASA | ValueboundChatbot with RASA | Valuebound
Chatbot with RASA | Valuebound
 
Drupal and Artificial Intelligence for Personalization
Drupal and Artificial Intelligence for Personalization Drupal and Artificial Intelligence for Personalization
Drupal and Artificial Intelligence for Personalization
 
Drupal growth in last year | Valuebound
Drupal growth in last year | ValueboundDrupal growth in last year | Valuebound
Drupal growth in last year | Valuebound
 
BE NEW TO THE WORLD "BRAVE FROM CHROME"
BE NEW TO THE WORLD "BRAVE FROM CHROME"BE NEW TO THE WORLD "BRAVE FROM CHROME"
BE NEW TO THE WORLD "BRAVE FROM CHROME"
 
Event loop in browser
Event loop in browserEvent loop in browser
Event loop in browser
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
 
Dependency Injection in Drupal 8
Dependency Injection in Drupal 8Dependency Injection in Drupal 8
Dependency Injection in Drupal 8
 
An Overview of Field Collection Views Module
An Overview of Field Collection Views ModuleAn Overview of Field Collection Views Module
An Overview of Field Collection Views Module
 

Dernier

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
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
 
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...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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...
 
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...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
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
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
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
 
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...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 

React JS: A Secret Preview

  • 1. React JS: A Secret Preview Prashant Sharma https://www.linkedin.com/in/response2prashant
  • 2. Agendas 1. Introduction 2. What is React JS? 3. What is Single Page Application? 4. Why React is better than other SPA? 5. React JS Setup 6. React JSX 7. ES6 Arrow Function 8. React Components 9. Component Life Cycle 10. Error Boundaries 11. React Higher Order Component (hoc) 12. Axios in React
  • 3. to be continued…. 12. Redux 13. Advantages of React JS 14. Disadvantages of React JS
  • 4. ● React is a front-end library developed by Facebook, in the year 2013. ● It is used for handling the view layer for web and mobile apps. ● ReactJS allows us to create reusable UI components. ● It is currently one of the most popular JavaScript libraries and has a strong foundation and large community behind it. Introduction
  • 5. ● React is a library for building composable user interfaces. ● It encourages the creation of reusable UI components, which present data that changes over time. ● React abstracts away the DOM from you, offering a simpler programming model and better performance. ● React can also render on the server using Node, and it can power native apps using React Native. ● React implements one-way reactive data flow, which reduces the boilerplate and is easier to reason about than traditional data binding. What is React JS ?
  • 6. What is Single Page Applications? A single-page application is an app that works inside a browser and does not require page reloading during use. You are using this type of applications every day. These are for instance: Gmail, Google Maps, Facebook and GitHub.
  • 7. ● There are various Single Page Applications Frameworks like Angularjs, Reactjs and Vuejs. ● Angularjs is a MVC framework . Angularjs is complicated in comparison to Reactjs and Vuejs but proper documentation available. ● Reactjs is a library not a framework and easy to learn but proper documentation is not available. Why React is better than other SPAs?
  • 8. ...to be continue ● High level of flexibility and maximum of responsiveness. ● Vue js describes itself as “The Progressive JavaScript Frameworks” and easy to learn in comparison to Angularjs and Reactjs. ● Lack of full english documentation. ● Vue js might have issues while integrating into huge projects.
  • 9. Step: 1 Install node in your system Step: 2 Open terminal type npm init react-app my-app Step: 3 type cd my-app Step: 4 type npm start Step: 5 Now you can start building react app. React configuration
  • 10. React JSX React uses JSX for templating instead of regular JavaScript. It is not necessary to use it, however, following are some pros that come with it. 1. It is faster because it performs optimization while compiling code to JavaScript. 2. It is also type-safe and most of the errors can be caught during compilation. 3. It makes it easier and faster to write templates, if you are familiar with HTML.
  • 11. ...to be continued import React, {Component} from 'react'; import Layout from './components/Layout/Layout.js'; import BurgerBuilder from './containers/BurgerBuilder/BurgerBuilder'; import { BrowserRouter, Route, link} from 'react-router-dom'; class App extends Component { render() { return ( <div> <BrowserRouter> <Layout> <Route path="/" exact component={BurgerBuilder} /> </Layout> </BrowserRouter> </div> ); } } export default App;
  • 12. ES6 Arrow Function arrowfunctionExample = () => { return( <div>Something</div> ); }
  • 13. Arrow function single parameter syntax: arrowfunctionExample = a => a*a; Arrow function double parameter syntax: arrowfunctionExample = (a,b) => a*b; Arrow function with JSX: arrowfunctionExample = () => (<div>Something</div>);
  • 14. ….to be continued Arrow function with multiple line: arrowfunctionExample = (a, b) =>{ const c = a+b; return ( <div>Something {c}</div> ); }
  • 15. React Components There are basically two types of component are used: 1. Stateful component 2. Stateless component
  • 16. ...to be continued Stateful components: import Backdrop from ‘backdrop’; class Person extends Component { state={ count: 0 } render(){ return( <div> {this.state.count <Backdrop show=”true” /> </div>); } } export default Person:
  • 17. ...to be continued Stateless components: Stateless components have not their own state always dependant upon another component. These components are reusable components. const backdrop = (props) => ( props.show ?<div className={classes.Backdrop} onClick={props.clicked}></div> : null );
  • 18. React Component Lifecycle ● We need more control over the stages that a component goes through. ● The process where all these stages are involved is called the component’s lifecycle and every React component goes through it. ● React provides several methods that notify us when certain stage of this process occurs. ● These methods are called the component’s lifecycle methods and they are invoked in a predictable order.
  • 19. ...to be continued Basically all the React component’s lifecyle methods can be split in four phases: initialization, mounting, updating and unmounting. Let’s take a closer look at each one of them. Initialization The initialization phase is where we define defaults and initial values for this.props and this.state by implementing getDefaultProps() and getInitialState() respectively.
  • 20. ...to be continued Mounting Mounting is the process that occurs when a component is being inserted into the DOM. This phase has two methods that we can hook up with: componentWillMount() and componentDidMount(). componentWillMount() method is first called in this phase. componentDidMount() is invoked second in this phase.
  • 21. ...to be continued Updating There are also methods that will allow us to execute code relative to when a component’s state or properties get updated. These methods are part of the updating phase and are called in the following order: componentWillReceiveProps() shouldComponentUpdate() componentWillUpdate() render() componentDidUpdate() When received new props from the parent.
  • 22. ...to be continued Unmounting In this phase React provide us with only one method: ● componentWillUnmount() It is called immediately before the component is unmounted from the DOM.
  • 23. Error Boundaries ● A JavaScript error in a part of the UI shouldn’t break the whole app. ● To solve this problem for React users, React 16 introduces a new concept of an “error boundary”. ● Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI instead of the component tree that crashed. ● Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.
  • 24. ...to be continued class ErroBoundary extends React.Component{ state= { hasError: false } componentDidCatch(error, info){ //Display fallback, UI this,setState({hasError:true}); // You can also log error to an error reporting service logErrorToMyService(error, info); } render(){ if(this.state.hasError){ return (<div>Something went wrong</div>); } return this.props.children; } }
  • 25. ...to be continued Then you can use it as a regular component <ErrorBoundary> <MyComponent /> </ErrorBoundary>
  • 26. React Higher Order Component ● A higher-order component in React is a pattern used to share common functionality between components without repeating code. ● A higher-order component is actually not a component though, it is a function. ● A HOC function takes a component as an argument and returns a component. ● It transforms a component into another component and adds additional data or functionality.
  • 27. ...to be continued const NewComponent = (BaseComponent) => { // ... create new component from old one and update return UpdatedComponent }
  • 28. Axios in React ● Every project needs to interact with a REST API at some stage. ● Axios provides interaction with REST API. ● With the help of AXIOS you can send GET, POST, PUT and DELETE request to the REST API and render response to our app. ● Axios is promise based.
  • 29. What is Redux? Redux is a predictable state container for JavaScript apps. Redux uses this concept of uni-directional data flow: ● The application has a central /root state. ● A state change triggers View updates. ● Only special functions can change the state. ● A user interaction triggers these special, state changing functions. ● Only one change takes place at a time.
  • 31. Advantages of React JS 1. Virtual DOM in ReactJS makes user experience better and developer’s work faster. 2. Permission to reuse React components significantly saves time. 3. One-direction data flow in ReactJS provides a stable code. 4. An open-source library: constantly developing and open to contributions.
  • 32. Disadvantages of React 1. High pace of development. 2. Poor documentation. 3. ‘HTML in my JavaScript!’ – JSX as a barrier.