React is a JavaScript library for building user interfaces that uses a virtual DOM for improved performance. It uses a one-way data flow and declarative components. The virtual DOM allows React to efficiently update the real DOM by only making necessary changes. Components in React encapsulate elements and can have state and props. JSX is recommended for writing React components and compiles to plain JavaScript.
Overview of React, its definition as a JavaScript library for UIs, motivation behind its creation, and introduction to Virtual DOM, the concept which plays a crucial role in performance.
Disadvantages of Real DOM manipulation, introduction of Virtual DOM, its update strategy in React, and the benefits such as minimal DOM calls and improved performance.
Key React terminology like React Elements and Components, introduction of JSX, and the recommended build tool Webpack for optimizing React applications.
Explanation of Props as parameters for components and how State holds component's current data, highlighting their importance in creating reusable components.
Detailed look at component lifecycle methods in React and how to specify component characteristics, ensuring proper data flow and rendering.
Key advantages of React such as composition of components, improved performance via synthetic events, and overall benefits of declarative nature.
Advantages of React's pure JavaScript nature over traditional frameworks, introduction of powerful tools like react-devtools for development, ensuring efficient building.
Expanding ecosystem surrounding React including tools and libraries such as Redux and React-Native, enhancing functionality and community support.
Formal closure of the presentation with a thank you note.
What is React
AJAVASCRIPT LIBRARY FOR BUILDING USER INTERFACES
Main Features
• Just V of MVC
• Virtual DOM
• One Way Data Flow
3.
Background of React
•Started by Facebook in 2013
• Motivation - building large applications with data that
changes over time.
• Over 40k+ Star on Github and 645 contributors
• You are in a good company
Source - https://github.com/facebook/react/wiki/Sites-Using-React
4.
Lets Get started
Themost important thing
Virtual DOM
To understand this We need to first see
Real DOM
The Reason for performance
React’s Virtual DOMStrategy
On every update to component
• React Builds New Virtual DOM Subtree
• Diff with the actual DOM
• Computes minimal DOM mutation
• Batch executes updates
Getting started withReact
React Terminology
React Elements
(Basic Building Block)
var root = React.createElement('div');
React.js Main React Library
react-dom.js
Supporting library to generate DOM
notation
Factories
(Called internally by React Element)
function createFactory(type) {
return React.createElement.bind(null, type);
}
React Nodes Tree of React Element
React Components
var MyComponent = React.createClass({
render: function() {
...
}
});
(Encapsulated React Elements)
(You will use this the most)
11.
React Recommends Useof JSX
What is JSX
ped, object-oriented programming language designed to run on m
In short
Its just like Type script and transpiles into Plain Javascript
Without JSX
With JSX
12.
Recommended Build Tool
Webpack
•Bundles JS using require.js
• Minification, Linting, Production Build
• Loaders system allows easy
extensibility
• Just like gulp but more powerful
• Lets us use ES6 and ES7 features
• React tags are transformed
automatically using babel-react-
presets module
Props
• Props arelike parameter to functions
• They make component super re-usable
• Way to pass info from one component to other component
• Includes props type validation to ensure sanity of data
Demo
15.
STATE
• Holds thecurrent state of the component
• Update in the state variable updates the component
• getInitialState and setState method for updating state
value
Demo
16.
Refs
• Used tokeep reference to components
• If callback function is passed, then callback is executed just
after the component mounts with component as parameter
• Possible application includes animation, finding specific
node
17.
Component Specification
• render-> Required method. Returns ReactElement
• getInitialState -> Not Required, If we require some
default state for component
• getDefaultProps -> Not Required. If we want to set
default value of prop.
• propTypes -> Not Required. Allows the prop type
validation
Demo
18.
Component Lifecycle
• componentWillMount-> Invoked before the initial rendering of component
• componentWillReceiveProps -> Invoked before the component receives the props
(not on initial render)
• componentDidUpdate -> Invoked immediately after the update of comports are
flushed to DOM
• componentDidMount -> Invoked after initial rendering of the component (Used
for fetching data from server)
• componentWillUpdate -> Called before rendering.
• shouldComponentUpdate -> Must return true (or) false. Called when new state (or)
props are being received.
• componentWillUnmount -> Called before component is unmounted
Advantages
Composition
• Rather thanbuilding one big component, React
allows to focus building mini components to
compose one big component out of it.
• Highly reusable code
21.
Synthetic events
• Onlysingle event listener is binded per component
• Results in less memory usage and improvement in perform
22.
Plain Javascript
• Directive
•digest cycle
• Transclude function
• $scope and $rootScope
• $scope.$apply
We have all suffered our way through
Not anymore
React is pure javascript
Less time learning and more time implementing