SlideShare a Scribd company logo
1 of 17
React JS
REACT.JS
•Library for Creating Interfaces
•Focus on the View
•Virtual DOM = JS Object: efficiently update & render components when data changes
•Components and subcomponents  nested structure (like HTML)
•Data Flow
•States store what is happening in application and react to changes in state or data
•Props used to pass information between main component and subcomponents
DOM (DOCUMENT OBJECT MODEL)
• Document Object Model makes every addressable item in a web page/interface an
Object that can be manipulated for color, transparency, position, sound and
behaviors.
• Every HTML Tag is a DOM object
DOM (DOCUMENT OBJECT
MODEL)
DOM
CSS
HTML
JavaScript
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"
crossorigin></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
</head>
<body>
<div id="mydiv"></div>
<script type="text/babel">
function Hello() {
return <h1>Hello World!</h1>;
}
ReactDOM.render(<Hello />, document.getElementById('mydiv'))
</script>
</body>
</html>
Associate with a
DOM object
REACT –EMBEDDED IN HTML FILE
REACT COMPONENTS –MAKING CLASSES
// Create a component name MessageComponent
var MessageComponent = React.createClass({
render: function() {
return (
<div>{this.props.message}</div>
);
}
});
// Render an instance of MessageCoponent into document body
ReactDOM.render(<MessageComponent message=“Hello!” />, document.body );
Like JavaScript functions, but work in
isolation and return HTML via a render()
function.
• accept arbitrary inputs (called “props”)
and return React elements describing
what should appear on the screen.
ReactDOM – render elements in the actual DOM using .render(*)
ReactDOM.render(<MyComponent />, document.getElementById("react-containe
Class Component
class MyComp extends React.Component { render () { HTML }}
ReactDOM.render(<MyComp />, location in DOM))
Annonymous inner class
Example with declared
class
Associate with a
DOM object
Associated DOM object retrieved with getElementById
REACT COMPONENTS –ANOTHER E XAMPLE
• UI elements changing dynamically
class Car extends React.Component {
render() {
return <h2>Hi, I am a Car!</h2>;
}
}
ReactDOM.render(<Car />, document.getElementById('root'));
REACT COMPONENTS: CLASS OR FUNCTION
• We have seen examples of “Class” Components
• There are also just simple “function” Components
(these are simpler)
Class Component Example
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}
Function Component Example
function Welcome(props) {
return <h1>Hello, {props.name}</h1
}
• TRY IT OUT IN W3
REACT COMPONENTS –CODE IN JS FILE
index.html
<HTML>
<HEAD> …..</HEAD
<BODY>
<div id=“root”>
</div>
</BODY>
Code in js file and associated with html fi
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
If done on command line:
src folder there is a file called App.js
CREATING A REACT APPLICATION
import logo from './logo.svg';
import './App.css’;
function App() {
return (
<div className="App">
<h1>Hello World!</h1>
</div> );
}
export default App;
Let’s edit the App() function to simply
Create a Hello World!
CREATING A REACT APPLICATION
REACT – JSX – WHAT IS IT
// we have been seeing JSX already –here is previous example
var MessageComponent = React.createClass({
render: function() {
return (
<div>{this.props.message}</div>
);
}
});
// Render an instance of MessageCoponent into document body
ReactDOM.render(
<MessageComponent message=“Hello!” />
document.body
);
JSX stands for JavaScript XML.
JSX allows us to write HTML in React.
JSX = is javascript XML
See W3 schools to learn more about writing JSX
Execute the expression 5 + 5:
const myelement = <h1>React is {5 + 5} times better with JSX</h1>;
REACT.JS – PROPERTIES
•Properties
•Class component: this.props contains props defined by caller of this component
•{this.props.text} inside JSX <MyComp text="Hello World"/>
const element = <Welcome name="Sara" />;
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
const element = <Welcome name="Sara" />;
ReactDOM.render( element, document.getElementById('root') );
HTML:
<div id="root"></div>
YOU CAN CALL JAVA FROM REACT –
HERE SEE USE OF JAVA DATE CLASS.
EXAMPLE, UPDATE EVERY 1 SECOND
– IT ONLY UPDATES WHAT IS
NECESSARY
LET’S MODIFY OUR PREVIOUS CLOCK
EXAMPLE TO USE PROPERTIES
function Clock(props)
{ return (
<div>
<h1>Hello, world!</h1>
<h2>It is {props.date.toLocaleTimeString()}.</h2>
</div> );
}
function tick() {
ReactDOM.render( <Clock date={new Date()} />,
document.getElementById('root') );
}
MORE MORE TO LEARN…GO TO REACT WEBSITE
Code extends Component,
• method called updateAndNotify that will set the background color state and then set it
back to the initial value after a second (1000ms),
• componentWillUnmount method to clear the timer up, and a render method. This code looks like
this:
class Label extends React.Component
state = { backgroundColour: "inherit" };
componentWillUnmount() { #lifecycle method
if (this.updateTimer)
{ clearTimeout(this.updateTimer); }
}
updateAndNotify = () => {
if (this.updateTimer) return;
this.setState({ backgroundColour: "#9b34ee" });
this.updateTimer = setTimeout(() => {
this.setState({ backgroundColour: "inherit" });
this.updateTimer = null;
}, 1000);
}
render() {
return (
<span className="label-text" style={{ backgroundColor: this.state.backgroundColour }}>
{this.props.text} </span>
);
}
}
LEARN REACT – SOME
RESOURCES
https://www.codecademy.com/lrn/react-101
https://css-tricks.com/learning-react-redux/
Webstorm:
https://www.jetbrains.com/help/idea/react.h
tml#creating_react_app_with_create_react_a
pp

More Related Content

Similar to React JS Library for Building Interactive Interfaces

react-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryreact-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryjanet736113
 
ReactJS for Programmers
ReactJS for ProgrammersReactJS for Programmers
ReactJS for ProgrammersDavid Rodenas
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
The Exciting Future Of React
The Exciting Future Of ReactThe Exciting Future Of React
The Exciting Future Of Reactkristijanmkd
 
Introduction to React for jQuery Developers
Introduction to React for jQuery DevelopersIntroduction to React for jQuery Developers
Introduction to React for jQuery DevelopersRonald Huereca
 
Combining Angular and React Together
Combining Angular and React TogetherCombining Angular and React Together
Combining Angular and React TogetherSebastian Pederiva
 
React Best Practices All Developers Should Follow in 2024.pdf
React Best Practices All Developers Should Follow in 2024.pdfReact Best Practices All Developers Should Follow in 2024.pdf
React Best Practices All Developers Should Follow in 2024.pdfBOSC Tech Labs
 
Getting Started with React v16
Getting Started with React v16Getting Started with React v16
Getting Started with React v16Benny Neugebauer
 
ReactJS - A quick introduction to Awesomeness
ReactJS - A quick introduction to AwesomenessReactJS - A quick introduction to Awesomeness
ReactJS - A quick introduction to AwesomenessRonny Haase
 
20171108 PDN HOL React Basics
20171108 PDN HOL React Basics20171108 PDN HOL React Basics
20171108 PDN HOL React BasicsRich Ross
 
ReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparisonReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparison500Tech
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAERon Reiter
 
Reactивная тяга
Reactивная тягаReactивная тяга
Reactивная тягаVitebsk Miniq
 

Similar to React JS Library for Building Interactive Interfaces (20)

react-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryreact-slides.pdf gives information about react library
react-slides.pdf gives information about react library
 
Intro to React.js
Intro to React.jsIntro to React.js
Intro to React.js
 
React js
React jsReact js
React js
 
ReactJS for Programmers
ReactJS for ProgrammersReactJS for Programmers
ReactJS for Programmers
 
Reactjs workshop
Reactjs workshopReactjs workshop
Reactjs workshop
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
React/Redux
React/ReduxReact/Redux
React/Redux
 
The Exciting Future Of React
The Exciting Future Of ReactThe Exciting Future Of React
The Exciting Future Of React
 
React
React React
React
 
Introduction to React for jQuery Developers
Introduction to React for jQuery DevelopersIntroduction to React for jQuery Developers
Introduction to React for jQuery Developers
 
Combining Angular and React Together
Combining Angular and React TogetherCombining Angular and React Together
Combining Angular and React Together
 
React Best Practices All Developers Should Follow in 2024.pdf
React Best Practices All Developers Should Follow in 2024.pdfReact Best Practices All Developers Should Follow in 2024.pdf
React Best Practices All Developers Should Follow in 2024.pdf
 
Getting Started with React v16
Getting Started with React v16Getting Started with React v16
Getting Started with React v16
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
ReactJS - A quick introduction to Awesomeness
ReactJS - A quick introduction to AwesomenessReactJS - A quick introduction to Awesomeness
ReactJS - A quick introduction to Awesomeness
 
Jquery 2
Jquery 2Jquery 2
Jquery 2
 
20171108 PDN HOL React Basics
20171108 PDN HOL React Basics20171108 PDN HOL React Basics
20171108 PDN HOL React Basics
 
ReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparisonReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparison
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAE
 
Reactивная тяга
Reactивная тягаReactивная тяга
Reactивная тяга
 

Recently uploaded

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 

Recently uploaded (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 

React JS Library for Building Interactive Interfaces

  • 2. REACT.JS •Library for Creating Interfaces •Focus on the View •Virtual DOM = JS Object: efficiently update & render components when data changes •Components and subcomponents  nested structure (like HTML) •Data Flow •States store what is happening in application and react to changes in state or data •Props used to pass information between main component and subcomponents
  • 3. DOM (DOCUMENT OBJECT MODEL) • Document Object Model makes every addressable item in a web page/interface an Object that can be manipulated for color, transparency, position, sound and behaviors. • Every HTML Tag is a DOM object
  • 5. <!DOCTYPE html> <html> <head> <script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script> <script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script> <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script> </head> <body> <div id="mydiv"></div> <script type="text/babel"> function Hello() { return <h1>Hello World!</h1>; } ReactDOM.render(<Hello />, document.getElementById('mydiv')) </script> </body> </html> Associate with a DOM object REACT –EMBEDDED IN HTML FILE
  • 6. REACT COMPONENTS –MAKING CLASSES // Create a component name MessageComponent var MessageComponent = React.createClass({ render: function() { return ( <div>{this.props.message}</div> ); } }); // Render an instance of MessageCoponent into document body ReactDOM.render(<MessageComponent message=“Hello!” />, document.body ); Like JavaScript functions, but work in isolation and return HTML via a render() function. • accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen. ReactDOM – render elements in the actual DOM using .render(*) ReactDOM.render(<MyComponent />, document.getElementById("react-containe Class Component class MyComp extends React.Component { render () { HTML }} ReactDOM.render(<MyComp />, location in DOM)) Annonymous inner class Example with declared class Associate with a DOM object Associated DOM object retrieved with getElementById
  • 7. REACT COMPONENTS –ANOTHER E XAMPLE • UI elements changing dynamically class Car extends React.Component { render() { return <h2>Hi, I am a Car!</h2>; } } ReactDOM.render(<Car />, document.getElementById('root'));
  • 8. REACT COMPONENTS: CLASS OR FUNCTION • We have seen examples of “Class” Components • There are also just simple “function” Components (these are simpler) Class Component Example class Welcome extends React.Component { render() { return <h1>Hello, {this.props.name}</h1>; } } Function Component Example function Welcome(props) { return <h1>Hello, {props.name}</h1 }
  • 9. • TRY IT OUT IN W3 REACT COMPONENTS –CODE IN JS FILE index.html <HTML> <HEAD> …..</HEAD <BODY> <div id=“root”> </div> </BODY> Code in js file and associated with html fi
  • 10. import logo from './logo.svg'; import './App.css'; function App() { return ( <div className="App"> <header className="App-header"> <img src={logo} className="App-logo" alt="logo" /> <p> Edit <code>src/App.js</code> and save to reload. </p> <a className="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer" > Learn React </a> </header> </div> ); } export default App; If done on command line: src folder there is a file called App.js CREATING A REACT APPLICATION
  • 11. import logo from './logo.svg'; import './App.css’; function App() { return ( <div className="App"> <h1>Hello World!</h1> </div> ); } export default App; Let’s edit the App() function to simply Create a Hello World! CREATING A REACT APPLICATION
  • 12. REACT – JSX – WHAT IS IT // we have been seeing JSX already –here is previous example var MessageComponent = React.createClass({ render: function() { return ( <div>{this.props.message}</div> ); } }); // Render an instance of MessageCoponent into document body ReactDOM.render( <MessageComponent message=“Hello!” /> document.body ); JSX stands for JavaScript XML. JSX allows us to write HTML in React. JSX = is javascript XML See W3 schools to learn more about writing JSX Execute the expression 5 + 5: const myelement = <h1>React is {5 + 5} times better with JSX</h1>;
  • 13. REACT.JS – PROPERTIES •Properties •Class component: this.props contains props defined by caller of this component •{this.props.text} inside JSX <MyComp text="Hello World"/> const element = <Welcome name="Sara" />; function Welcome(props) { return <h1>Hello, {props.name}</h1>; } const element = <Welcome name="Sara" />; ReactDOM.render( element, document.getElementById('root') ); HTML: <div id="root"></div>
  • 14. YOU CAN CALL JAVA FROM REACT – HERE SEE USE OF JAVA DATE CLASS. EXAMPLE, UPDATE EVERY 1 SECOND – IT ONLY UPDATES WHAT IS NECESSARY
  • 15. LET’S MODIFY OUR PREVIOUS CLOCK EXAMPLE TO USE PROPERTIES function Clock(props) { return ( <div> <h1>Hello, world!</h1> <h2>It is {props.date.toLocaleTimeString()}.</h2> </div> ); } function tick() { ReactDOM.render( <Clock date={new Date()} />, document.getElementById('root') ); }
  • 16. MORE MORE TO LEARN…GO TO REACT WEBSITE Code extends Component, • method called updateAndNotify that will set the background color state and then set it back to the initial value after a second (1000ms), • componentWillUnmount method to clear the timer up, and a render method. This code looks like this: class Label extends React.Component state = { backgroundColour: "inherit" }; componentWillUnmount() { #lifecycle method if (this.updateTimer) { clearTimeout(this.updateTimer); } } updateAndNotify = () => { if (this.updateTimer) return; this.setState({ backgroundColour: "#9b34ee" }); this.updateTimer = setTimeout(() => { this.setState({ backgroundColour: "inherit" }); this.updateTimer = null; }, 1000); } render() { return ( <span className="label-text" style={{ backgroundColor: this.state.backgroundColour }}> {this.props.text} </span> ); } }
  • 17. LEARN REACT – SOME RESOURCES https://www.codecademy.com/lrn/react-101 https://css-tricks.com/learning-react-redux/ Webstorm: https://www.jetbrains.com/help/idea/react.h tml#creating_react_app_with_create_react_a pp