SlideShare a Scribd company logo
1 of 60
Introduction to
React
Day - 1
=
2
React Js
React is a javascript library for building
interactive User Interface( UI ).
3
4
Lorem Ipsum
Lorem IpsumLorem Ipsum
Lorem Ipsum Lorem Ipsum Lorem Ipsum
Lorem Ipsum Lorem Ipsum Lorem Ipsum
Root Element
<html>
Element
<body>
Element
<head>
Element
<title>
Element
<h1>
Element
<p>
Text Node
“Page title”
Text Node
“My heading”
Text Node
“My Paragraph
DOM
What makes React so fast?
5
6
Virtual DOM
Virtual DOM
7
8
Virtual DOM
9
patch
Virtual DOM
10
Why is React fast?
11
Why is React so fast?
What is a Virtual
DOM?
A Javascript Object that is a
“virtual”, representation of the “real”
DOM.
12
Why use react?
● Updates and renders only the elements that
change/update in the DOM( hence quick rendering )
● Build encapsulated components that manage their own
state.
● React can also render on the server using Node and
powerful mobile apps using react native.
13
History of React
● Created by Jordan Walke, a software engineer at
Facebook
● First deployed on Facebook's newsfeed in 2011 and later
on Instagram.com in 2012
● Open-sourced at JSConf US in May 2013
● Facebook announced React Fiber, on April 18, 2017
● React 360 V1.0.0 was released to the public on April 19,
2017
14
1- Add React in a Minute (Using React Scripts )
2- Using create-react-app
3- Using Parcel
4- Using Webpack and Babel
Set up React App
15
Day - 2
=
16
Class Based Components
Extend React Component Class and
it requires us to use render()
React Components
Functional Based Components
Are pure JavaScript function that
accepts props as its argument, and
returns some JSX
17
Components allow you to split the UI into independent reusable pieces of
JS codes.
Class Based Components
Functional Based Components
18
JSX ( JavaScript-XML )
● JSX is a XML-like syntax extension to JavaScript that creates
React elements.
● Its makes your code human readable, otherwise we had to
use React.createElement()
● Gives us expressiveness of JavaScript along with HTML like
template syntax.
19
Examples of using JSX
20
State of a Component
21
Virtual DOM
State of a Component
22
Virtual DOM
State of a Component
23
Virtual DOM
State of a Component
24
Virtual DOM
setState()
State of a Component
25
Virtual DOM
setState()
State of a Component
26
Virtual DOM
setState()
State of a Component
27
setState()
patch
Virtual DOM
What is a component
state?
● A State of a component is an object, that holds some
information that may change throughout the component
lifecycle.
● We define initial state and then we just have to notify that the
state is changed and the react will automatically render the
those changes on the front end behind the scenes.
● Every time the state changes the changes get re rendered so
the UI( front end ) changes automatically.
28
Props
● Props are inputs to components.
● Single values or objects containing a set of values that are passed to
components on creation, using a naming convention similar to HTML-tag
attributes
● They are used to:
1-Pass custom data to your component.
2-Trigger state changes.
29
Important Points
● React may batch multiple setState() calls into a single update
for performance.
● Because this.props and this.state may be updated
asynchronously, you should not rely on their values for
calculating the next state
● State is local or encapsulated. It is not accessible to any
component other than the one that owns and sets it.
● A component may choose to pass its state down as props to
its child components
● Imagine a component tree as a waterfall of props, each
component’s state is like an additional water source that
joins it at an arbitrary point but also flows down
30
Difference between State & Props
Props
=Props is passed by the parent to the
Child components
-A component should never modify its
own props
Component State
=State is managed within a
component for internal
communication
- State can be modified using
setState() and when value of state
changes render() is called.
31
The props( properties ) and state are both JavaScript objects. Props are like an
args of a function and states are like local variables inside the function
Parent, Child &
Nested Components
32
Create & Handle
Routes
33
Component LifeCycle
Mounting
- Component is constructed
with the given Props and
default state. This is done
inside constructor()
-Component came into the
DOM
Updating
- When the state of a
component is updated
34
Every React Component has a lifecycle of its own, which has different stages.
Unmounting
- Component is
removed from the
page
35
Constructor
● Overrides the constructor of React.Component
● Required only when we initialize state or bind methods.
E.g. this.handleClick = this.handleClick.bind(this);
● Call super(props) before any other statement.
● Do not call setState() inside it
36
getDerivedStateFromProps
● Invoked right before calling the render method
● Called both on the initial mount and on subsequent updates
● Should return an object to update the state, or null to update
nothing.
● Rare use cases where the state depends on changes in props
37
ComponentDidMount
● Load data from a remote endpoint
● Calling setState() here will trigger an extra rendering, but it
will happen before the browser updates the screen.
38
shouldComponentUpdate
● Exists as a performance optimization
● Not called for the initial render or when forceUpdate() is
used.
● Use built-in PureComponent instead of writing
shouldComponentUpdate()
● PureComponent performs a shallow comparison of props
and state, and reduces the chance that you’ll skip a
necessary update.
39
render
● Required method in a class component
● Should return React Elements ( JSX ) or Arrays and
fragments or Portals or String and numbers or Booleans or
null
● Should not modify component state
● It does not directly interact with the browser.
40
getSnapshotBeforeUpdate
● Invoked right before the most recently rendered output is
committed to e.g. the DOM
● Capture some information from the DOM (e.g. scroll position)
before it is potentially changed
● Returned value will be passed as a parameter to
componentDidUpdate()
● Example to use it: A chat thread that need to handle scroll
position in a special way.
41
ComponentDidUpdate
● Invoked immediately after updating occurs.
● Calling setState() here will trigger an extra rendering, but it
will happen before the browser updates the screen.
● setState() can be called but it must be wrapped in a
condition.
● If getSnapshotBeforeUpdate() is implemented, snapshot
param will be available, else undefined.
42
ComponentWillUnmount
● invoked immediately before a component is unmounted.
● For e.g. Invalidating timers, canceling network requests, or
cleaning up any subscriptions.
● should not call setState() as component will never be
rerendered.
43
Handling forms and
input values
44
Arrow functions and
Spread Operators
45
Day - 3
=
46
Reconciliation
● When a component’s props or state change,
React decides whether an actual DOM update is necessary
by comparing,
newly returned element = previously rendered one. ?
When they are not equal, React will update the DOM
47
HOC
● A function that takes a component and returns a new
component.
● Advanced technique in React for reusing component logic.
● Not part of the React API
● A pattern that emerges from React’s compositional nature.
48
Pure Components
● React.PureComponent implements it with a shallow prop
and state comparison and does not re-render if the they
don’t change.
● So it handles shouldComponentUpdate() for you
● Does not re-render if nextState = prevState
49
Memo
● React.memo is a higher order component.
● Similar to React.PureComponent but for functional based
components instead of classes.
● If your function component renders the same result given
the same props, you can wrap it in a call to React.memo
50
Use of Refs
● React.createRef creates a reference that can be attached
to React elements via the ref attribute.
● Avoid using jQuery as you have to import the jQuery library.
as we’re going to manipulate the dom
● Compared to using jQuery, elements can be faster
referenced in a React way using Refs
● Refs are not present during the initial render. You can
initialize it in constructor. However you must use it inside
one of the React’s lifecycle events such as
componentDidMount or componentDidUpdate.
51
52
Context
● Universal centralized data for your application.
● Used to share data, such as the current authenticated user,
theme, or preferred language, between components.
● We can avoid passing props through intermediate
elements
53
1-Create Context
54
2-Wrap in
Provider and
pass the state
to child
component
3-Wrap in Consumer and receive
context in Child Components
Pros of Context
● Set context on top and all the components in the middle
don’t have to know anything about it
● The one down at the bottom can access it
● Fills the same need as redux.
57
Cons of Context
● Makes debugging difficult
● Difficult to figure out what caused the error when you cannot
see the data in the child components that is not importing
Context
● You have to look at all the components which are
Consuming it to figure out which one of them caused the
problem
● Use context only when you have to.
58
Difference between Component
state & Store state
Component State
=State is managed within
a component
- State value can change,
and then render function
is called.
Store state
=Store State is updated,
by the reducer, when an
action is triggered.
59
60
Thanks!
Any questions?
@imranhsayed
@imran_.sayed

More Related Content

What's hot

Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_jsMicroPyramid .
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to ReactRob Quick
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS 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 ITnamespaceit
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Previewvaluebound
 
React js programming concept
React js programming conceptReact js programming concept
React js programming conceptTariqul islam
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core ConceptsDivyang Bhambhani
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorialMohammed Fazuluddin
 
React Context API
React Context APIReact Context API
React Context APINodeXperts
 
React.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOMReact.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOMJimit Shah
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux IntroductionNikolaus Graf
 

What's hot (20)

Intro to React
Intro to ReactIntro to React
Intro to React
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
 
Reactjs
Reactjs Reactjs
Reactjs
 
Introduction to React
Introduction to ReactIntroduction to React
Introduction to React
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS 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
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
React hooks
React hooksReact hooks
React hooks
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
React js - The Core Concepts
React js - The Core ConceptsReact js - The Core Concepts
React js - The Core Concepts
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
 
React Context API
React Context APIReact Context API
React Context API
 
React js
React jsReact js
React js
 
React.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOMReact.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOM
 
Reactjs
ReactjsReactjs
Reactjs
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
React js
React jsReact js
React js
 

Similar to React workshop

React Workshop: Core concepts of react
React Workshop: Core concepts of reactReact Workshop: Core concepts of react
React Workshop: Core concepts of reactImran Sayed
 
React and Flux life cycle with JSX, React Router and Jest Unit Testing
React and  Flux life cycle with JSX, React Router and Jest Unit TestingReact and  Flux life cycle with JSX, React Router and Jest Unit Testing
React and Flux life cycle with JSX, React Router and Jest Unit TestingEswara Kumar Palakollu
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react jsStephieJohn
 
Globant development week / React Redux Rorkshop
Globant development week / React Redux RorkshopGlobant development week / React Redux Rorkshop
Globant development week / React Redux RorkshopGlobant
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019iFour Technolab Pvt. Ltd.
 
React, Flux and more (p1)
React, Flux and more (p1)React, Flux and more (p1)
React, Flux and more (p1)tuanpa206
 
Optimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayoOptimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayoShedrack Akintayo
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesWalking Tree Technologies
 
Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"Flipkart
 
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.pdfStephieJohn
 
React - The JavaScript Library for User Interfaces
React - The JavaScript Library for User InterfacesReact - The JavaScript Library for User Interfaces
React - The JavaScript Library for User InterfacesJumping Bean
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today Nitin Tyagi
 
Getting started with react &amp; redux
Getting started with react &amp; reduxGetting started with react &amp; redux
Getting started with react &amp; reduxGirish Talekar
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥Remo Jansen
 
Spfx with react redux
Spfx with react reduxSpfx with react redux
Spfx with react reduxRajesh Kumar
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsANKUSH CHAVAN
 

Similar to React workshop (20)

React Workshop: Core concepts of react
React Workshop: Core concepts of reactReact Workshop: Core concepts of react
React Workshop: Core concepts of react
 
React and Flux life cycle with JSX, React Router and Jest Unit Testing
React and  Flux life cycle with JSX, React Router and Jest Unit TestingReact and  Flux life cycle with JSX, React Router and Jest Unit Testing
React and Flux life cycle with JSX, React Router and Jest Unit Testing
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
Globant development week / React Redux Rorkshop
Globant development week / React Redux RorkshopGlobant development week / React Redux Rorkshop
Globant development week / React Redux Rorkshop
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019Meetup  - Getting Started with MVVM Light for WPF - 11 may 2019
Meetup - Getting Started with MVVM Light for WPF - 11 may 2019
 
React, Flux and more (p1)
React, Flux and more (p1)React, Flux and more (p1)
React, Flux and more (p1)
 
Optimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayoOptimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayo
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree Technologies
 
Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"
 
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
 
ReactJS (1)
ReactJS (1)ReactJS (1)
ReactJS (1)
 
React - The JavaScript Library for User Interfaces
React - The JavaScript Library for User InterfacesReact - The JavaScript Library for User Interfaces
React - The JavaScript Library for User Interfaces
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
 
Presentation1
Presentation1Presentation1
Presentation1
 
Getting started with react &amp; redux
Getting started with react &amp; reduxGetting started with react &amp; redux
Getting started with react &amp; redux
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
Spfx with react redux
Spfx with react reduxSpfx with react redux
Spfx with react redux
 
Redux workshop
Redux workshopRedux workshop
Redux workshop
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle Methods
 

More from Imran Sayed

Docker with WordPress
Docker with WordPressDocker with WordPress
Docker with WordPressImran Sayed
 
Why Progressive Web Apps For WordPress - WordCamp Finland
Why Progressive Web Apps For WordPress - WordCamp FinlandWhy Progressive Web Apps For WordPress - WordCamp Finland
Why Progressive Web Apps For WordPress - WordCamp FinlandImran Sayed
 
Custom gutenberg block development in react
Custom gutenberg block development in reactCustom gutenberg block development in react
Custom gutenberg block development in reactImran Sayed
 
Fastest Way of Creating Gutenberg Blocks - WordCamp Rochester
Fastest Way of Creating Gutenberg Blocks - WordCamp RochesterFastest Way of Creating Gutenberg Blocks - WordCamp Rochester
Fastest Way of Creating Gutenberg Blocks - WordCamp RochesterImran Sayed
 
Harness The Power Of ACF For Gatsby and WordPress
Harness The Power Of ACF For Gatsby and WordPressHarness The Power Of ACF For Gatsby and WordPress
Harness The Power Of ACF For Gatsby and WordPressImran Sayed
 
Improving Your Debugging Skills In WordPress
Improving Your Debugging Skills In WordPressImproving Your Debugging Skills In WordPress
Improving Your Debugging Skills In WordPressImran Sayed
 
Build Modern Web Applications with React and WordPress
Build Modern Web Applications with React and WordPressBuild Modern Web Applications with React and WordPress
Build Modern Web Applications with React and WordPressImran Sayed
 
Why progressive apps for WordPress - WordSesh 2020
Why progressive apps for WordPress - WordSesh 2020Why progressive apps for WordPress - WordSesh 2020
Why progressive apps for WordPress - WordSesh 2020Imran Sayed
 
Digging Into Gutenberg
Digging Into GutenbergDigging Into Gutenberg
Digging Into GutenbergImran Sayed
 
Fastest Way Of Creating Gutenberg Blocks With Minimal JavaScript Knowledge ...
Fastest Way Of Creating  Gutenberg Blocks  With Minimal JavaScript Knowledge ...Fastest Way Of Creating  Gutenberg Blocks  With Minimal JavaScript Knowledge ...
Fastest Way Of Creating Gutenberg Blocks With Minimal JavaScript Knowledge ...Imran Sayed
 
Why progressive web apps for word press wc-ahemdabad
Why progressive web apps for word press wc-ahemdabadWhy progressive web apps for word press wc-ahemdabad
Why progressive web apps for word press wc-ahemdabadImran Sayed
 
Build fast word press site in react in 30 mins with frontity
Build fast word press site in react in 30 mins   with frontityBuild fast word press site in react in 30 mins   with frontity
Build fast word press site in react in 30 mins with frontityImran Sayed
 
Build Fast WordPress Site With Gatsby
Build Fast WordPress Site With GatsbyBuild Fast WordPress Site With Gatsby
Build Fast WordPress Site With GatsbyImran Sayed
 
Why Progressive Apps For WordPress?
Why Progressive Apps For WordPress?Why Progressive Apps For WordPress?
Why Progressive Apps For WordPress?Imran Sayed
 
Creating Gutenberg Blocks With ACF
Creating Gutenberg Blocks With ACFCreating Gutenberg Blocks With ACF
Creating Gutenberg Blocks With ACFImran Sayed
 
Custom gutenberg block development with React
Custom gutenberg block development with ReactCustom gutenberg block development with React
Custom gutenberg block development with ReactImran Sayed
 
SSR with React - Connecting Next.js with WordPress
SSR with React - Connecting Next.js with WordPressSSR with React - Connecting Next.js with WordPress
SSR with React - Connecting Next.js with WordPressImran Sayed
 
React with WordPress : Headless CMS
React with WordPress : Headless CMSReact with WordPress : Headless CMS
React with WordPress : Headless CMSImran Sayed
 
Introduction to Gutenberg- Imran Sayed
Introduction to Gutenberg- Imran SayedIntroduction to Gutenberg- Imran Sayed
Introduction to Gutenberg- Imran SayedImran Sayed
 

More from Imran Sayed (19)

Docker with WordPress
Docker with WordPressDocker with WordPress
Docker with WordPress
 
Why Progressive Web Apps For WordPress - WordCamp Finland
Why Progressive Web Apps For WordPress - WordCamp FinlandWhy Progressive Web Apps For WordPress - WordCamp Finland
Why Progressive Web Apps For WordPress - WordCamp Finland
 
Custom gutenberg block development in react
Custom gutenberg block development in reactCustom gutenberg block development in react
Custom gutenberg block development in react
 
Fastest Way of Creating Gutenberg Blocks - WordCamp Rochester
Fastest Way of Creating Gutenberg Blocks - WordCamp RochesterFastest Way of Creating Gutenberg Blocks - WordCamp Rochester
Fastest Way of Creating Gutenberg Blocks - WordCamp Rochester
 
Harness The Power Of ACF For Gatsby and WordPress
Harness The Power Of ACF For Gatsby and WordPressHarness The Power Of ACF For Gatsby and WordPress
Harness The Power Of ACF For Gatsby and WordPress
 
Improving Your Debugging Skills In WordPress
Improving Your Debugging Skills In WordPressImproving Your Debugging Skills In WordPress
Improving Your Debugging Skills In WordPress
 
Build Modern Web Applications with React and WordPress
Build Modern Web Applications with React and WordPressBuild Modern Web Applications with React and WordPress
Build Modern Web Applications with React and WordPress
 
Why progressive apps for WordPress - WordSesh 2020
Why progressive apps for WordPress - WordSesh 2020Why progressive apps for WordPress - WordSesh 2020
Why progressive apps for WordPress - WordSesh 2020
 
Digging Into Gutenberg
Digging Into GutenbergDigging Into Gutenberg
Digging Into Gutenberg
 
Fastest Way Of Creating Gutenberg Blocks With Minimal JavaScript Knowledge ...
Fastest Way Of Creating  Gutenberg Blocks  With Minimal JavaScript Knowledge ...Fastest Way Of Creating  Gutenberg Blocks  With Minimal JavaScript Knowledge ...
Fastest Way Of Creating Gutenberg Blocks With Minimal JavaScript Knowledge ...
 
Why progressive web apps for word press wc-ahemdabad
Why progressive web apps for word press wc-ahemdabadWhy progressive web apps for word press wc-ahemdabad
Why progressive web apps for word press wc-ahemdabad
 
Build fast word press site in react in 30 mins with frontity
Build fast word press site in react in 30 mins   with frontityBuild fast word press site in react in 30 mins   with frontity
Build fast word press site in react in 30 mins with frontity
 
Build Fast WordPress Site With Gatsby
Build Fast WordPress Site With GatsbyBuild Fast WordPress Site With Gatsby
Build Fast WordPress Site With Gatsby
 
Why Progressive Apps For WordPress?
Why Progressive Apps For WordPress?Why Progressive Apps For WordPress?
Why Progressive Apps For WordPress?
 
Creating Gutenberg Blocks With ACF
Creating Gutenberg Blocks With ACFCreating Gutenberg Blocks With ACF
Creating Gutenberg Blocks With ACF
 
Custom gutenberg block development with React
Custom gutenberg block development with ReactCustom gutenberg block development with React
Custom gutenberg block development with React
 
SSR with React - Connecting Next.js with WordPress
SSR with React - Connecting Next.js with WordPressSSR with React - Connecting Next.js with WordPress
SSR with React - Connecting Next.js with WordPress
 
React with WordPress : Headless CMS
React with WordPress : Headless CMSReact with WordPress : Headless CMS
React with WordPress : Headless CMS
 
Introduction to Gutenberg- Imran Sayed
Introduction to Gutenberg- Imran SayedIntroduction to Gutenberg- Imran Sayed
Introduction to Gutenberg- Imran Sayed
 

Recently uploaded

WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 

Recently uploaded (20)

WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 

React workshop

  • 3. React Js React is a javascript library for building interactive User Interface( UI ). 3
  • 4. 4 Lorem Ipsum Lorem IpsumLorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Root Element <html> Element <body> Element <head> Element <title> Element <h1> Element <p> Text Node “Page title” Text Node “My heading” Text Node “My Paragraph DOM
  • 5. What makes React so fast? 5
  • 11. 11 Why is React so fast?
  • 12. What is a Virtual DOM? A Javascript Object that is a “virtual”, representation of the “real” DOM. 12
  • 13. Why use react? ● Updates and renders only the elements that change/update in the DOM( hence quick rendering ) ● Build encapsulated components that manage their own state. ● React can also render on the server using Node and powerful mobile apps using react native. 13
  • 14. History of React ● Created by Jordan Walke, a software engineer at Facebook ● First deployed on Facebook's newsfeed in 2011 and later on Instagram.com in 2012 ● Open-sourced at JSConf US in May 2013 ● Facebook announced React Fiber, on April 18, 2017 ● React 360 V1.0.0 was released to the public on April 19, 2017 14
  • 15. 1- Add React in a Minute (Using React Scripts ) 2- Using create-react-app 3- Using Parcel 4- Using Webpack and Babel Set up React App 15
  • 17. Class Based Components Extend React Component Class and it requires us to use render() React Components Functional Based Components Are pure JavaScript function that accepts props as its argument, and returns some JSX 17 Components allow you to split the UI into independent reusable pieces of JS codes.
  • 18. Class Based Components Functional Based Components 18
  • 19. JSX ( JavaScript-XML ) ● JSX is a XML-like syntax extension to JavaScript that creates React elements. ● Its makes your code human readable, otherwise we had to use React.createElement() ● Gives us expressiveness of JavaScript along with HTML like template syntax. 19
  • 21. State of a Component 21 Virtual DOM
  • 22. State of a Component 22 Virtual DOM
  • 23. State of a Component 23 Virtual DOM
  • 24. State of a Component 24 Virtual DOM setState()
  • 25. State of a Component 25 Virtual DOM setState()
  • 26. State of a Component 26 Virtual DOM setState()
  • 27. State of a Component 27 setState() patch Virtual DOM
  • 28. What is a component state? ● A State of a component is an object, that holds some information that may change throughout the component lifecycle. ● We define initial state and then we just have to notify that the state is changed and the react will automatically render the those changes on the front end behind the scenes. ● Every time the state changes the changes get re rendered so the UI( front end ) changes automatically. 28
  • 29. Props ● Props are inputs to components. ● Single values or objects containing a set of values that are passed to components on creation, using a naming convention similar to HTML-tag attributes ● They are used to: 1-Pass custom data to your component. 2-Trigger state changes. 29
  • 30. Important Points ● React may batch multiple setState() calls into a single update for performance. ● Because this.props and this.state may be updated asynchronously, you should not rely on their values for calculating the next state ● State is local or encapsulated. It is not accessible to any component other than the one that owns and sets it. ● A component may choose to pass its state down as props to its child components ● Imagine a component tree as a waterfall of props, each component’s state is like an additional water source that joins it at an arbitrary point but also flows down 30
  • 31. Difference between State & Props Props =Props is passed by the parent to the Child components -A component should never modify its own props Component State =State is managed within a component for internal communication - State can be modified using setState() and when value of state changes render() is called. 31 The props( properties ) and state are both JavaScript objects. Props are like an args of a function and states are like local variables inside the function
  • 32. Parent, Child & Nested Components 32
  • 34. Component LifeCycle Mounting - Component is constructed with the given Props and default state. This is done inside constructor() -Component came into the DOM Updating - When the state of a component is updated 34 Every React Component has a lifecycle of its own, which has different stages. Unmounting - Component is removed from the page
  • 35. 35
  • 36. Constructor ● Overrides the constructor of React.Component ● Required only when we initialize state or bind methods. E.g. this.handleClick = this.handleClick.bind(this); ● Call super(props) before any other statement. ● Do not call setState() inside it 36
  • 37. getDerivedStateFromProps ● Invoked right before calling the render method ● Called both on the initial mount and on subsequent updates ● Should return an object to update the state, or null to update nothing. ● Rare use cases where the state depends on changes in props 37
  • 38. ComponentDidMount ● Load data from a remote endpoint ● Calling setState() here will trigger an extra rendering, but it will happen before the browser updates the screen. 38
  • 39. shouldComponentUpdate ● Exists as a performance optimization ● Not called for the initial render or when forceUpdate() is used. ● Use built-in PureComponent instead of writing shouldComponentUpdate() ● PureComponent performs a shallow comparison of props and state, and reduces the chance that you’ll skip a necessary update. 39
  • 40. render ● Required method in a class component ● Should return React Elements ( JSX ) or Arrays and fragments or Portals or String and numbers or Booleans or null ● Should not modify component state ● It does not directly interact with the browser. 40
  • 41. getSnapshotBeforeUpdate ● Invoked right before the most recently rendered output is committed to e.g. the DOM ● Capture some information from the DOM (e.g. scroll position) before it is potentially changed ● Returned value will be passed as a parameter to componentDidUpdate() ● Example to use it: A chat thread that need to handle scroll position in a special way. 41
  • 42. ComponentDidUpdate ● Invoked immediately after updating occurs. ● Calling setState() here will trigger an extra rendering, but it will happen before the browser updates the screen. ● setState() can be called but it must be wrapped in a condition. ● If getSnapshotBeforeUpdate() is implemented, snapshot param will be available, else undefined. 42
  • 43. ComponentWillUnmount ● invoked immediately before a component is unmounted. ● For e.g. Invalidating timers, canceling network requests, or cleaning up any subscriptions. ● should not call setState() as component will never be rerendered. 43
  • 47. Reconciliation ● When a component’s props or state change, React decides whether an actual DOM update is necessary by comparing, newly returned element = previously rendered one. ? When they are not equal, React will update the DOM 47
  • 48. HOC ● A function that takes a component and returns a new component. ● Advanced technique in React for reusing component logic. ● Not part of the React API ● A pattern that emerges from React’s compositional nature. 48
  • 49. Pure Components ● React.PureComponent implements it with a shallow prop and state comparison and does not re-render if the they don’t change. ● So it handles shouldComponentUpdate() for you ● Does not re-render if nextState = prevState 49
  • 50. Memo ● React.memo is a higher order component. ● Similar to React.PureComponent but for functional based components instead of classes. ● If your function component renders the same result given the same props, you can wrap it in a call to React.memo 50
  • 51. Use of Refs ● React.createRef creates a reference that can be attached to React elements via the ref attribute. ● Avoid using jQuery as you have to import the jQuery library. as we’re going to manipulate the dom ● Compared to using jQuery, elements can be faster referenced in a React way using Refs ● Refs are not present during the initial render. You can initialize it in constructor. However you must use it inside one of the React’s lifecycle events such as componentDidMount or componentDidUpdate. 51
  • 52. 52
  • 53. Context ● Universal centralized data for your application. ● Used to share data, such as the current authenticated user, theme, or preferred language, between components. ● We can avoid passing props through intermediate elements 53
  • 55. 2-Wrap in Provider and pass the state to child component
  • 56. 3-Wrap in Consumer and receive context in Child Components
  • 57. Pros of Context ● Set context on top and all the components in the middle don’t have to know anything about it ● The one down at the bottom can access it ● Fills the same need as redux. 57
  • 58. Cons of Context ● Makes debugging difficult ● Difficult to figure out what caused the error when you cannot see the data in the child components that is not importing Context ● You have to look at all the components which are Consuming it to figure out which one of them caused the problem ● Use context only when you have to. 58
  • 59. Difference between Component state & Store state Component State =State is managed within a component - State value can change, and then render function is called. Store state =Store State is updated, by the reducer, when an action is triggered. 59