Professional Documents
Culture Documents
www.netlink.com
• Introduction
• Setup Environment
Prerequisites:-
✓ HTML
✓ CSS
✓ JavaScript
1. Unified UX
2. Fluid UX
3. Loosely Coupled & Extensible
4. Simplified Deployment & Upgrade
SPA(Single Page Application)
❑JavaScript
❑JQuery
❑Angular
❑React
Limitations of JQuery & JavaScript
➢ JS, JQ lot of DOM manipulation
➢ Lot of coding
➢ Lot of references
➢ Heavy
➢ Slow
What is solution?
https://nodejs.org/en/download/
https://code.visualstudio.com/
React in existing web application
A typical react application requires the following tool chain:-
❑Compiler-----------------------Babel
❑Core Library-------------------React
❑Virtual DOM Library---------React
❑Web Pack
❑Rendering Engine/View
❑Testing Tool
A typical react application requires the following tool chain:-
❑Core Library-------------------React
❑Compiler-----------------------Babel
✓ Open your PC locations
✓ Create a new folder for project “C:\WebApp”
✓ Open “WebApp” folder in “Visual Studio Code”
✓ Open Terminal in VS-Code
Method 2-- You can also use “npx create-react-app”, which doesn’t
require to install “create-react-app” tool
npx create-react-app yourAppName
e.g. npx create-react-app react-shopping-app
npm start
React is component based.
➢ A pre-defined logic and presentation which you can implement and use in any application.
➢ A component comprises of
o Presentation - HTML
o Logic - TS/JS/JSX
o Style – CSS
➢ A component is re-usable.
JSX in React Components
➢ “Stateful” components are of the class type, while “Stateless” components are of
the function type.
➢ In React, function components are a way to write components that only contain a render method and don't
have their own state.
➢ They are simply JavaScript functions that may or may not receive data as parameters.
➢ We can create a function that takes props(properties) as input and returns what should be rendered.
➢ The functional component is also known as a stateless component because they do not hold or manage
state.
➢ Class components are more complex than functional components.It requires you to extend from React.
➢ You can pass data from one class to other class components.
➢ You can create a class by defining a class that extends Component and has a render function. It can render
virtual DOM elements by using “render()” method.
➢ The class component is also known as a stateful component because they can hold or manage local state.
➢ Class Component is just a JavaScript class that extends “React.Component” base class.
JavaScript class comprises only
o Properties
o Methods
o Accessors
o Constructor
1. Create a file called “Class.js” and write the
following code.
Syntax:
class ComponentName extends React.Component
{
constructor(props) {
super(props);
this.state = {
key : value
}
} - State key can contain any type of value: Primitive or
} Non-Primitive.
- You can access state with reference of key.
Syntax:
this.state.key
Set Value into State Object:
To set value into state object we have to use "setState()" of "React.Component" base.
• The default state of a class component is not accessible to any method in the class.
• You have to bind the methods with class in order to set state.
• Binding of method with class can be defined in various ways
UpdateName(event){
console.log(`Hello ! ${event.target.value}`);
}
Syntax : State
constructor()
{
this.UpdateName = this.UpdateName.bind(this);
}
React Properties in Components
Syntax:
➢ You can't use css attributes directly, you have to configure as dynamic property using "camel case".
fetch("api url")
Syntax:
.then(response => response.json())
.then(data => {
store data, display data
})
➢jQuery provide Ajax methods to consume data from API.
➢jQuery supports all operations like GET, POST, PUT,
DELETE
➢ jQuery returns data in JSON format.
➢$.ajax()
➢$.getJSON()
Install jquery:
npm install jquery
Axios
➢ Returns data in JSON format.
➢ It supports all request methods.
➢ It uses "sync & async" techniques.
➢ It uses unblocking technique, It executes the given task along with other tasks.
➢ It handles CORS issues.
➢ It handles XSS [Cross Site Scripting Attacks]
➢ It handles multiple requests with one method.
Install axios:
Syntax:
<form onSubmit={handleSubmit}>
<input type="text" onChange={(e)=> {setName(e.target.value)}} value={Name}/>
<button type="submit"> Submit </button>
</form>
3rd Party React Forms
- Formik
- Kendo Forms
- React-Form
- NewForms
- ValueLink
- etc..
Routing URL:
http://www.amazon.in/electronics/mobiles/samsung/12000
• Routing uses "Ajax" calls, which allows to load content async.
• Routing allows to load new content into page without reloading the page.
• SPA uses routing technique, so that user can stay on one page and get access to everything on to
the page without navigating out of page.
• Routing makes the page fluid.
• Routing can be defined
• a) Server Side
• b) Client Side
Syntax:
<Router>
<Route path="" component={} /> // outlet
</Router>
<Router>
<Switch>
<Route path="" exact component={} /> // outlet
</Switch>
</Router>
Upgrade to React Router v6
1. Uninstall route 5
> npm uninstall react-router-dom@5.2
2. Install route 6
3. Route 6 Provides Browser Router Component that reduces browser compatibility issues
<BrowserRouter>
<Router>
</Router>
</BrowserRouter>
4. Route 6 doesn't require <Switch> you have to configure all routes in "<Routes>" collection
<Routes>
<Route />
<Route />
</Routes>
1. Embedded Technique
Single file comprises of logic, presentation and styles.
2. Module Technique
Component can be separated into Logic, Styles and HTML files.