SlideShare ist ein Scribd-Unternehmen logo
1 von 23
React
Introduction to React
By Angela Lehru
@LehruAJay
What is React
A Javascript library for building user interfaces like web applications.
React can be used as a base in the development of single-page applications.
Create and Render a React Element
const element = React.createElement(
'h1',
{
id: 'main-title',
title: 'This is a title'
},
'Hello World'
)
ReactDOM.render(element, document.getElementById('root'));
React Dom
A library that lets React connect to and update the DOM
JSX
A syntax extension to Javascript that is used with React to describe elements in
the UI. As we’ll see, it resembles writing HTML.
We need Babel to transpile JSX into Javascript to be rendered on the browser. Try
it out babeljs.io/repl
To add Babel in a project:
<html/><head/> - <script src="https://unpkg.com/babel-
standalone@6.15.0/babel.min.js"></script>
<html/><head/> - <script type="text/babel" src="app.js"></script>
Set up a development server
Install http-server
1. npm init -y
2. npm i -S http-server
Add a start script to the package.json
"scripts": {
"start": "http-server"
},
Create React Project
create-react-app is an abstract way of getting started on a React Project. It
configures:
- Development server
- Webpack
- Babel
To install via command line/terminal:
npx create-react-app project-name
Let’s build an Inventory App
Components
Components
A typical functional component
import React, { Component, Fragment} from 'react';
const HelloWorld () {
return (
<h1>Hello World</h1>
);
}
export default HelloWorld;
State
A class component
import React, { Component, Fragment} from 'react';
class MainBody extends Component {
state = {
value:0
}
formatCount() {
return this.state.value === 0 ? 'Zero' : this.state.value
}
render() {
return (
<Fragment>
<span>{this.formatCount()}</span>
...
</Fragment>
);
}
}
export default MainBody;
Handling events
import React, { Component, Fragment} from 'react';
class MainBody extends Component {
state = {
count:0
}
handleIncrement () {
console.log(‘Add clicked’)
}
render() {
return (
<Fragment>
<button onClick={this.handleIncrement}>Add</button>
...
</Fragment>
);
}
export default MainBody;
Updating state
this.setState({ value: state})
import React, { Component, Fragment} from 'react';
class MainBody extends Component {
state = {
value:0
}
handleIncrement = () => {
console.log(‘Add clicked’, this.state.value)
}
render() {
return (
<Fragment>
<button onClick={this.handleIncrement}>Add</button>
...
</Fragment>
);
}
export default MainBody;
Parent - Child Components
import React, { Component, Fragment} from 'react';
class Items extends Component {
render() {
return (
<Fragment>
<Item />
<Item />
<Item />
</Fragment>
);
}
export default MainBody;
Rendering Lists
import React, { Component, Fragment} from 'react';
class MainBody extends Component {
state = {
tags: [tag1, tag2, tag3]
}
render() {
return (
<Fragment>
<ul>{this.state.tags.map(tag => <li key={tag}>{tag}</li>}</ul>
...
</Fragment>
);
}
export default MainBody;
Parent - Child Components
import React, { Component, Fragment} from 'react';
import MainBody from './components/mainBody';
class Items extends Component {
state = {
items: [
{ id: 1, value: 1 }
}
render() {
return (
<Fragment>
{this.state.items.map(item =>
<MainBody key={item.id} value={item.value}></MainBody>)}
</Fragment>
);
}
export default Items;
Passing Data to components(props)
import React, { Component, Fragment} from 'react';
class MainBody extends Component {
state = {
value:this.props.value
}
render() {
return (
<Fragment>
...
</Fragment>
);
}
export default Items;
Passing Children
Special prop called children, we use when we want to pass something between
the opening and closing tags of an element
1. Pass element in the component
2. Pass{this.props.children}in the parent component
<MainBody><h4>Item #{counter.id}</h4></MainBody>
React Tree
Props Vs State
Stateless Functional Components
Resources
Link to source code - Github repo
References used:
https://www.youtube.com/watch?v=Ke90Tje7VS0
https://reactjs.org/docs/
Questions

Weitere ähnliche Inhalte

Was ist angesagt?

Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developerEugene Zharkov
 
Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 DreamLab
 
Better web apps with React and Redux
Better web apps with React and ReduxBetter web apps with React and Redux
Better web apps with React and ReduxAli Sa'o
 
ReactJs presentation
ReactJs presentationReactJs presentation
ReactJs presentationnishasowdri
 
React for Dummies
React for DummiesReact for Dummies
React for DummiesMitch Chen
 
Creating a WYSIWYG Editor with React
Creating a WYSIWYG Editor with ReactCreating a WYSIWYG Editor with React
Creating a WYSIWYG Editor with Reactpeychevi
 
React.js and Redux overview
React.js and Redux overviewReact.js and Redux overview
React.js and Redux overviewAlex Bachuk
 
Introduction to React & Redux
Introduction to React & ReduxIntroduction to React & Redux
Introduction to React & ReduxBoris Dinkevich
 
Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2DreamLab
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max PetruckMaksym Petruk
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners Varun Raj
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxVisual Engineering
 

Was ist angesagt? (20)

Switch to React.js from AngularJS developer
Switch to React.js from AngularJS developerSwitch to React.js from AngularJS developer
Switch to React.js from AngularJS developer
 
React with Redux
React with ReduxReact with Redux
React with Redux
 
Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3
 
Better web apps with React and Redux
Better web apps with React and ReduxBetter web apps with React and Redux
Better web apps with React and Redux
 
ReactJs presentation
ReactJs presentationReactJs presentation
ReactJs presentation
 
React и redux
React и reduxReact и redux
React и redux
 
React & redux
React & reduxReact & redux
React & redux
 
React for Dummies
React for DummiesReact for Dummies
React for Dummies
 
Creating a WYSIWYG Editor with React
Creating a WYSIWYG Editor with ReactCreating a WYSIWYG Editor with React
Creating a WYSIWYG Editor with React
 
React redux
React reduxReact redux
React redux
 
React.js and Redux overview
React.js and Redux overviewReact.js and Redux overview
React.js and Redux overview
 
Intro to ReactJS
Intro to ReactJSIntro to ReactJS
Intro to ReactJS
 
Introduction to React & Redux
Introduction to React & ReduxIntroduction to React & Redux
Introduction to React & Redux
 
React render props
React render propsReact render props
React render props
 
React and redux
React and reduxReact and redux
React and redux
 
Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max Petruck
 
Redux vs Alt
Redux vs AltRedux vs Alt
Redux vs Alt
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
 
Workshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & ReduxWorkshop 20: ReactJS Part II Flux Pattern & Redux
Workshop 20: ReactJS Part II Flux Pattern & Redux
 

Ähnlich wie React outbox

React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs[T]echdencias
 
Getting Started with React v16
Getting Started with React v16Getting Started with React v16
Getting Started with React v16Benny Neugebauer
 
Manage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxManage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxCommit University
 
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...Luciano Mammino
 
Server side rendering with React and Symfony
Server side rendering with React and SymfonyServer side rendering with React and Symfony
Server side rendering with React and SymfonyIgnacio Martín
 
Introduction to React for Frontend Developers
Introduction to React for Frontend DevelopersIntroduction to React for Frontend Developers
Introduction to React for Frontend DevelopersSergio Nakamura
 
Introduction to React and MobX
Introduction to React and MobXIntroduction to React and MobX
Introduction to React and MobXAnjali Chawla
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Elyse Kolker Gordon
 
Build web apps with react js
Build web apps with react jsBuild web apps with react js
Build web apps with react jsdhanushkacnd
 
Reactивная тяга
Reactивная тягаReactивная тяга
Reactивная тягаVitebsk Miniq
 
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4Rob Tweed
 
Intro to React | DreamLab Academy
Intro to React | DreamLab AcademyIntro to React | DreamLab Academy
Intro to React | DreamLab AcademyDreamLab
 
Stay with React.js in 2020
Stay with React.js in 2020Stay with React.js in 2020
Stay with React.js in 2020Jerry Liao
 
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3Rob Tweed
 

Ähnlich wie React outbox (20)

React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
 
Getting Started with React v16
Getting Started with React v16Getting Started with React v16
Getting Started with React v16
 
Manage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's ReduxManage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's Redux
 
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
 
Server side rendering with React and Symfony
Server side rendering with React and SymfonyServer side rendering with React and Symfony
Server side rendering with React and Symfony
 
Introduction to React for Frontend Developers
Introduction to React for Frontend DevelopersIntroduction to React for Frontend Developers
Introduction to React for Frontend Developers
 
Introduction to React and MobX
Introduction to React and MobXIntroduction to React and MobX
Introduction to React and MobX
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017
 
ReactJS
ReactJSReactJS
ReactJS
 
React lecture
React lectureReact lecture
React lecture
 
Build web apps with react js
Build web apps with react jsBuild web apps with react js
Build web apps with react js
 
Reactивная тяга
Reactивная тягаReactивная тяга
Reactивная тяга
 
Intro react js
Intro react jsIntro react js
Intro react js
 
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
EWD 3 Training Course Part 38: Building a React.js application with QEWD, Part 4
 
React js
React jsReact js
React js
 
Intro to React | DreamLab Academy
Intro to React | DreamLab AcademyIntro to React | DreamLab Academy
Intro to React | DreamLab Academy
 
React 101
React 101React 101
React 101
 
Let's react - Meetup
Let's react - MeetupLet's react - Meetup
Let's react - Meetup
 
Stay with React.js in 2020
Stay with React.js in 2020Stay with React.js in 2020
Stay with React.js in 2020
 
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
EWD 3 Training Course Part 39: Building a React.js application with QEWD, Part 3
 

Kürzlich hochgeladen

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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 RobisonAnna Loughnan Colquhoun
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 

Kürzlich hochgeladen (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 

React outbox

  • 1. React Introduction to React By Angela Lehru @LehruAJay
  • 2. What is React A Javascript library for building user interfaces like web applications. React can be used as a base in the development of single-page applications.
  • 3. Create and Render a React Element const element = React.createElement( 'h1', { id: 'main-title', title: 'This is a title' }, 'Hello World' ) ReactDOM.render(element, document.getElementById('root'));
  • 4. React Dom A library that lets React connect to and update the DOM
  • 5. JSX A syntax extension to Javascript that is used with React to describe elements in the UI. As we’ll see, it resembles writing HTML. We need Babel to transpile JSX into Javascript to be rendered on the browser. Try it out babeljs.io/repl To add Babel in a project: <html/><head/> - <script src="https://unpkg.com/babel- standalone@6.15.0/babel.min.js"></script> <html/><head/> - <script type="text/babel" src="app.js"></script>
  • 6. Set up a development server Install http-server 1. npm init -y 2. npm i -S http-server Add a start script to the package.json "scripts": { "start": "http-server" },
  • 7. Create React Project create-react-app is an abstract way of getting started on a React Project. It configures: - Development server - Webpack - Babel To install via command line/terminal: npx create-react-app project-name
  • 8. Let’s build an Inventory App
  • 10. Components A typical functional component import React, { Component, Fragment} from 'react'; const HelloWorld () { return ( <h1>Hello World</h1> ); } export default HelloWorld;
  • 11. State A class component import React, { Component, Fragment} from 'react'; class MainBody extends Component { state = { value:0 } formatCount() { return this.state.value === 0 ? 'Zero' : this.state.value } render() { return ( <Fragment> <span>{this.formatCount()}</span> ... </Fragment> ); } } export default MainBody;
  • 12. Handling events import React, { Component, Fragment} from 'react'; class MainBody extends Component { state = { count:0 } handleIncrement () { console.log(‘Add clicked’) } render() { return ( <Fragment> <button onClick={this.handleIncrement}>Add</button> ... </Fragment> ); } export default MainBody;
  • 13. Updating state this.setState({ value: state}) import React, { Component, Fragment} from 'react'; class MainBody extends Component { state = { value:0 } handleIncrement = () => { console.log(‘Add clicked’, this.state.value) } render() { return ( <Fragment> <button onClick={this.handleIncrement}>Add</button> ... </Fragment> ); } export default MainBody;
  • 14. Parent - Child Components import React, { Component, Fragment} from 'react'; class Items extends Component { render() { return ( <Fragment> <Item /> <Item /> <Item /> </Fragment> ); } export default MainBody;
  • 15. Rendering Lists import React, { Component, Fragment} from 'react'; class MainBody extends Component { state = { tags: [tag1, tag2, tag3] } render() { return ( <Fragment> <ul>{this.state.tags.map(tag => <li key={tag}>{tag}</li>}</ul> ... </Fragment> ); } export default MainBody;
  • 16. Parent - Child Components import React, { Component, Fragment} from 'react'; import MainBody from './components/mainBody'; class Items extends Component { state = { items: [ { id: 1, value: 1 } } render() { return ( <Fragment> {this.state.items.map(item => <MainBody key={item.id} value={item.value}></MainBody>)} </Fragment> ); } export default Items;
  • 17. Passing Data to components(props) import React, { Component, Fragment} from 'react'; class MainBody extends Component { state = { value:this.props.value } render() { return ( <Fragment> ... </Fragment> ); } export default Items;
  • 18. Passing Children Special prop called children, we use when we want to pass something between the opening and closing tags of an element 1. Pass element in the component 2. Pass{this.props.children}in the parent component <MainBody><h4>Item #{counter.id}</h4></MainBody>
  • 22. Resources Link to source code - Github repo References used: https://www.youtube.com/watch?v=Ke90Tje7VS0 https://reactjs.org/docs/

Hinweis der Redaktion

  1. A single-page application (SPA) is a web application or web site that interacts with the user by dynamically rewriting the current page rather than loading entire new pages from a server. This approach avoids interruption of the user experience between successive pages.
  2. Add react to a website https://reactjs.org/docs/add-react-to-a-website.html
  3. The createElement() method creates and returns a React element of the given type React doesn’t create actual DOM nodes. React creates objects that describe DOM nodes The ReactDOM.render() method renders React elements to the DOM React doesn’t manipulate and update the DOM directly. React only manages what gets rendered to the DOM via ReactDOM.render(). It’s the job of render() to interpret the element objects and create DOM nodes out of them.
  4. Webpack for bundling our files Babel for compiling our JSX into javascript
  5. Create Navbar and render it in App.js
  6. Arrow functions -> to access this.state.value Update state -> this.setState({ value: this.state.value + 1 })
  7. {this.state.counters.map(counter => <MainBody key={counter.id} value={counter.value}> <h4>Item #{counter.id}</h4> </MainBody>)}