React Lecture Part 1
React Lecture Part 1
Lecture 1
By Mona Soliman
Agenda
● Introduction about React
● Single page application
● Virtual Dom
● Environment setup
● React app structure
● What is JSX ?
● Building Reusable components
● Component lifecycle methods
● State and Props.
● Handling events
an open-source JavaScript library
that is used for building user
Why React?
interfaces specifically for
single-page applications.
1-High Performance
ReactJS main feature i.e Virtual
React first deployed on Facebook’s DOM that results in high
newsfeed in 2011 and on performance of the app
Instagram.com in 2012.
2-Easy to learn.
A class component should be used whenever you need to work with state, it
might be relay or internal react state. Whenever you need to fetch data before
you render your component you should call a fetchData function in
componentDidMount.
Class component vs Functional component
a functional component has no state, no lifecycle methods and it’s easy to
write(plain function), a class component has state, lifecycle methods and
React creates an instance of a class component every time React renders it. If
you don’t need to use state or lifecycle I would recommend you to use a
function component, but If there’s a chance that you need one of those
things(state, lifecycle methods) I would suggest you to use class component
Component lifecycle
Each component goes through
three phases:
1. Mounting
2. updating
3. unmounting
Component lifecycle
Props and state
<button onClick={adduser}>Click
Me</button>
Handling events
<button onClick={() =>
this.handleClick()}>Click Me</button>
Thank you