SlideShare a Scribd company logo
USING REACT WITH METEOR
by Neha
What we will Learn
● Simple Rendering
● Updating
● Conditional Rendering
React JSX
JSX
● JSX is a syntax extension to JavaScript.
● Its tag syntax is neither a string nor HTML, e.g.
const element = <h1>Hello, world!</h1>;
● You can embed any JavaScript expression in JSX
● By wrapping it in curly braces, e.g.
○ {2 + 2}
JSX
function getGreeting(user) {
if (user) {
return <h1>Hello, {formatName(user)}!</h1>;
}
return <h1>Hello, Stranger.</h1>;
}
After compilation, JSX expressions become regular JS objects.
So we can:
● Use JSX inside if statements and for loops
● Assign it to variables
JSX
Specifying Attributes with JSX:
● String literals with quotes:
const element = <div className="container"></div>;
● JS expressions with curly braces:
const element = <img src={user.avatarUrl}></img>;
● React DOM uses camelCase property naming convention
Setup Meteor App
Setup Meteor App
● Create meteor app:
○ meteor create react-workshop
OR download starter files: https://goo.gl/gYHDUL
● Remove blaze and other packages:
○ meteor remove blaze-html-templates autopublish insecure
● Add React:
Adding React Component
Component: App.jsx
// Add: imports/ui/components/App.jsx
import React from 'react';
import { Meteor } from 'meteor/meteor';
export default class App extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div id="container">
{/* some html elements here */}
</div>
);
}
}
Simple Rendering
React DOM
What is React DOM?
● React DOM uses Virtual DOM concept
● It is used to manipulate the contents of our app view
● DOM-specific methods can be used at the top level of
our app
● Used via react-dom package
ReactDOM.render()
DOM Specific React Method:
● Renders a React element into the DOM in the supplied
container
● Return a reference to the component
● Controls the contents of the container node you pass
in.
Rendering an Element into the DOM
● Create a <div> in your HTML file:
○ <div id="app"></div>
● This is a "root" DOM node
● Everything inside it will be managed by React DOM.
client/main.html
<!-- client/main.html -->
<head>
<title>Player Stats</title>
</head>
<body>
<!-- React root node -->
<div id="app"></div>
<!-- React root node ends -->
</body>
client/main.js
// client/main.js
import { Meteor } from 'meteor/meteor';
import React from 'react';
import { render } from 'react-dom';
import App from '../imports/ui/components/App.jsx';
// Render simple react component at startup
Meteor.startup(() => {
render(<App />, document.getElementById('app'));
});
Rendering React Element
(Simple text render)
// imports/ui/components/App.jsx
// ...
render() {
const staticText = 'Meteor Noida';
return (
<div id="container">
<b>Static Text:</b> {staticText}
</div>
);
}
Run the Meteor
app!
Updating
Updating React Element
(Text box, update state)
Add State:
// imports/ui/components/App.jsx
// ...
constructor(props) {
super(props);
this.state = {
text: 'Hello Meteorites!',
};
}
// ...
Updating React Element
(Text box, update state)
Update render function:
// imports/ui/components/App.jsx
render() {
// ...
const { text } = this.state;
return (
// ...
<div id="container">
<b>Dynamic Text:</b> {text}
<br />
</div>
// ...
);
}
Updating React Element
(Text box, update state)
Add input box:
// imports/ui/components/App.jsx
<div id="container">
<b>Dynamic Text:</b> {text}
<br />
<input
type="text"
name="updateText"
value={text}
onChange={this.updateText.bind(this)}
/>
</div> See the React DOM
updates in action!
Updating React Element
(Text box, update state)
Add state handler:
// imports/ui/components/App.jsx
export default class App extends React.Component {
constructor(props) {
// ...
}
updateText(e) {
const text = e.target.value;
this.setState({ text });
}
render() {
// …
}
}
React Only Updates What's Necessary
React DOM:
● Compares the element and its children to the
previous one
● Only applies the DOM updates necessary
● To bring the DOM to the desired state.
Conditional Rendering
Conditional Rendering
(Checkbox to show text)
// imports/ui/components/App.jsx
constructor(props) {
super(props);
this.state = {
text: 'Hello Meteorites!',
show: true,
};
}
Conditional Rendering
(Checkbox to show text)
render() {
const { text, show } = this.state;
// ...
return (
<div id="container">
{/* ... */}
{/* Checkbox to show input text box */}
<b>Show Input Box:</b>
<input
type="checkbox"
name="showInputBox"
checked={show}
onChange={this.toggleInputBox.bind(this)}
/>
<br /><br />
{/* ... */}
</div>
);
}
}
Conditional Rendering
(Checkbox to show text)
// State handler for checkbox
toggleInputBox(e) {
const show = e.target.checked;
this.setState({ show });
}
Conditional Rendering
(Checkbox to show text)
<div id="container">
{/* ... */}
{/* Conditionally render input text box based on checkbox value */}
{
show
? <div>
<input
type="text"
name="updateText"
value={text}
onChange={this.updateText.bind(this)}
/>
<br />
</div>
: null
}
{/* ... */}
</div>
See the Conditional
Rendering in action!

More Related Content

What's hot (20)

PPTX
React with Redux
Stanimir Todorov
 
PPTX
REACT.JS : Rethinking UI Development Using JavaScript
Deepu S Nath
 
PDF
React for Dummies
Mitch Chen
 
PPT
Repetition is bad, repetition is bad.
Michele Giacobazzi
 
PDF
Workshop 3: JavaScript build tools
Visual Engineering
 
PDF
React.js and Redux overview
Alex Bachuk
 
PPT
7\9 SSIS 2008R2_Training - Script Task
Pramod Singla
 
PDF
Mobile Day - React Native
Software Guru
 
PDF
How to build to do app using vue composition api and vuex 4 with typescript
Katy Slemon
 
PDF
React redux
Michel Perez
 
PDF
Async JavaScript Unit Testing
Mihail Gaberov
 
PDF
Asyc flow control with javascript generators - redux-saga
Pedro Solá
 
PDF
Let's Redux!
Joseph Chiang
 
PDF
Rapid development tools for java ee 8 [tut2998]
Payara
 
PPTX
Sqladria 2009 SRC
tepsum
 
PDF
Stay with React.js in 2020
Jerry Liao
 
PDF
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
Alessandro Molina
 
PDF
Rapid Development Tools for Java EE 8 [TUT2998]
Gaurav Gupta
 
PDF
Reactive & Realtime Web Applications with TurboGears2
Alessandro Molina
 
PPTX
Redux workshop
Imran Sayed
 
React with Redux
Stanimir Todorov
 
REACT.JS : Rethinking UI Development Using JavaScript
Deepu S Nath
 
React for Dummies
Mitch Chen
 
Repetition is bad, repetition is bad.
Michele Giacobazzi
 
Workshop 3: JavaScript build tools
Visual Engineering
 
React.js and Redux overview
Alex Bachuk
 
7\9 SSIS 2008R2_Training - Script Task
Pramod Singla
 
Mobile Day - React Native
Software Guru
 
How to build to do app using vue composition api and vuex 4 with typescript
Katy Slemon
 
React redux
Michel Perez
 
Async JavaScript Unit Testing
Mihail Gaberov
 
Asyc flow control with javascript generators - redux-saga
Pedro Solá
 
Let's Redux!
Joseph Chiang
 
Rapid development tools for java ee 8 [tut2998]
Payara
 
Sqladria 2009 SRC
tepsum
 
Stay with React.js in 2020
Jerry Liao
 
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
Alessandro Molina
 
Rapid Development Tools for Java EE 8 [TUT2998]
Gaurav Gupta
 
Reactive & Realtime Web Applications with TurboGears2
Alessandro Molina
 
Redux workshop
Imran Sayed
 

Similar to Using react with meteor (20)

PPTX
MeteorJS Session
Shreyans Gandhi
 
PPTX
Meteor
Noam Kfir
 
PDF
Introduction to React for Frontend Developers
Sergio Nakamura
 
PDF
React enlightenment
George salu da silva
 
PPTX
20171108 PDN HOL React Basics
Rich Ross
 
PDF
react.pdf
yihunie2
 
PDF
0900 learning-react
RohitYadav696
 
PPTX
Getting Started with React v16
Benny Neugebauer
 
PDF
Introduction to React JS
Bethmi Gunasekara
 
PDF
ReactJS for Programmers
David Rodenas
 
PPTX
Meteor Day Talk
Brandon Bechtel
 
PDF
ReactJS presentation
Thanh Tuong
 
PDF
React js
Rajesh Kolla
 
PPTX
Up and Running with ReactJS
Loc Nguyen
 
PPT
ReactJS.ppt
MOMEKEMKUEFOUETDUREL
 
PPTX
Mastering React: Building Modern and Interactive User Interfaces
medtechno1999
 
PDF
React talk, GrunnJs 24 September 2014
_jjoos_
 
PDF
Server side rendering with React and Symfony
Ignacio Martín
 
PPTX
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
zmulani8
 
PDF
Learn react by Etietop Demas
Etietop Demas
 
MeteorJS Session
Shreyans Gandhi
 
Meteor
Noam Kfir
 
Introduction to React for Frontend Developers
Sergio Nakamura
 
React enlightenment
George salu da silva
 
20171108 PDN HOL React Basics
Rich Ross
 
react.pdf
yihunie2
 
0900 learning-react
RohitYadav696
 
Getting Started with React v16
Benny Neugebauer
 
Introduction to React JS
Bethmi Gunasekara
 
ReactJS for Programmers
David Rodenas
 
Meteor Day Talk
Brandon Bechtel
 
ReactJS presentation
Thanh Tuong
 
React js
Rajesh Kolla
 
Up and Running with ReactJS
Loc Nguyen
 
Mastering React: Building Modern and Interactive User Interfaces
medtechno1999
 
React talk, GrunnJs 24 September 2014
_jjoos_
 
Server side rendering with React and Symfony
Ignacio Martín
 
NEXTjs.pptxfggfgfdgfgfdgfdgfdgfdgfdgfdgfg
zmulani8
 
Learn react by Etietop Demas
Etietop Demas
 
Ad

More from NodeXperts (20)

PDF
ECMA Script
NodeXperts
 
PDF
Apollo Server IV
NodeXperts
 
PDF
React Context API
NodeXperts
 
PDF
Devops - Microservice and Kubernetes
NodeXperts
 
PDF
Introduction to EC2 (AWS)
NodeXperts
 
PDF
Reactive Application Using METEOR
NodeXperts
 
PDF
Apollo server II
NodeXperts
 
PDF
Apollo Server
NodeXperts
 
PDF
Apollo Server III
NodeXperts
 
PPTX
Getting Reactive Data
NodeXperts
 
PPTX
State, Life cycle, Methods & Events
NodeXperts
 
PPTX
Refs in react
NodeXperts
 
PPTX
Flow router, components and props
NodeXperts
 
PPTX
Introduction to Reactjs
NodeXperts
 
PPTX
Mobile apps using meteor - Part 1
NodeXperts
 
PPTX
Microservice architecture : Part 1
NodeXperts
 
PPTX
Reactive web applications using MeteorJS
NodeXperts
 
PPTX
Improving build solutions dependency management with webpack
NodeXperts
 
PPTX
Meteor workshop
NodeXperts
 
PPTX
Introduction to meteor
NodeXperts
 
ECMA Script
NodeXperts
 
Apollo Server IV
NodeXperts
 
React Context API
NodeXperts
 
Devops - Microservice and Kubernetes
NodeXperts
 
Introduction to EC2 (AWS)
NodeXperts
 
Reactive Application Using METEOR
NodeXperts
 
Apollo server II
NodeXperts
 
Apollo Server
NodeXperts
 
Apollo Server III
NodeXperts
 
Getting Reactive Data
NodeXperts
 
State, Life cycle, Methods & Events
NodeXperts
 
Refs in react
NodeXperts
 
Flow router, components and props
NodeXperts
 
Introduction to Reactjs
NodeXperts
 
Mobile apps using meteor - Part 1
NodeXperts
 
Microservice architecture : Part 1
NodeXperts
 
Reactive web applications using MeteorJS
NodeXperts
 
Improving build solutions dependency management with webpack
NodeXperts
 
Meteor workshop
NodeXperts
 
Introduction to meteor
NodeXperts
 
Ad

Recently uploaded (20)

PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Digital Circuits, important subject in CS
contactparinay1
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 

Using react with meteor

  • 1. USING REACT WITH METEOR by Neha
  • 2. What we will Learn ● Simple Rendering ● Updating ● Conditional Rendering
  • 4. JSX ● JSX is a syntax extension to JavaScript. ● Its tag syntax is neither a string nor HTML, e.g. const element = <h1>Hello, world!</h1>; ● You can embed any JavaScript expression in JSX ● By wrapping it in curly braces, e.g. ○ {2 + 2}
  • 5. JSX function getGreeting(user) { if (user) { return <h1>Hello, {formatName(user)}!</h1>; } return <h1>Hello, Stranger.</h1>; } After compilation, JSX expressions become regular JS objects. So we can: ● Use JSX inside if statements and for loops ● Assign it to variables
  • 6. JSX Specifying Attributes with JSX: ● String literals with quotes: const element = <div className="container"></div>; ● JS expressions with curly braces: const element = <img src={user.avatarUrl}></img>; ● React DOM uses camelCase property naming convention
  • 8. Setup Meteor App ● Create meteor app: ○ meteor create react-workshop OR download starter files: https://goo.gl/gYHDUL ● Remove blaze and other packages: ○ meteor remove blaze-html-templates autopublish insecure ● Add React:
  • 10. Component: App.jsx // Add: imports/ui/components/App.jsx import React from 'react'; import { Meteor } from 'meteor/meteor'; export default class App extends React.Component { constructor(props) { super(props); } render() { return ( <div id="container"> {/* some html elements here */} </div> ); } }
  • 12. React DOM What is React DOM? ● React DOM uses Virtual DOM concept ● It is used to manipulate the contents of our app view ● DOM-specific methods can be used at the top level of our app ● Used via react-dom package
  • 13. ReactDOM.render() DOM Specific React Method: ● Renders a React element into the DOM in the supplied container ● Return a reference to the component ● Controls the contents of the container node you pass in.
  • 14. Rendering an Element into the DOM ● Create a <div> in your HTML file: ○ <div id="app"></div> ● This is a "root" DOM node ● Everything inside it will be managed by React DOM.
  • 15. client/main.html <!-- client/main.html --> <head> <title>Player Stats</title> </head> <body> <!-- React root node --> <div id="app"></div> <!-- React root node ends --> </body>
  • 16. client/main.js // client/main.js import { Meteor } from 'meteor/meteor'; import React from 'react'; import { render } from 'react-dom'; import App from '../imports/ui/components/App.jsx'; // Render simple react component at startup Meteor.startup(() => { render(<App />, document.getElementById('app')); });
  • 17. Rendering React Element (Simple text render) // imports/ui/components/App.jsx // ... render() { const staticText = 'Meteor Noida'; return ( <div id="container"> <b>Static Text:</b> {staticText} </div> ); } Run the Meteor app!
  • 19. Updating React Element (Text box, update state) Add State: // imports/ui/components/App.jsx // ... constructor(props) { super(props); this.state = { text: 'Hello Meteorites!', }; } // ...
  • 20. Updating React Element (Text box, update state) Update render function: // imports/ui/components/App.jsx render() { // ... const { text } = this.state; return ( // ... <div id="container"> <b>Dynamic Text:</b> {text} <br /> </div> // ... ); }
  • 21. Updating React Element (Text box, update state) Add input box: // imports/ui/components/App.jsx <div id="container"> <b>Dynamic Text:</b> {text} <br /> <input type="text" name="updateText" value={text} onChange={this.updateText.bind(this)} /> </div> See the React DOM updates in action!
  • 22. Updating React Element (Text box, update state) Add state handler: // imports/ui/components/App.jsx export default class App extends React.Component { constructor(props) { // ... } updateText(e) { const text = e.target.value; this.setState({ text }); } render() { // … } }
  • 23. React Only Updates What's Necessary React DOM: ● Compares the element and its children to the previous one ● Only applies the DOM updates necessary ● To bring the DOM to the desired state.
  • 25. Conditional Rendering (Checkbox to show text) // imports/ui/components/App.jsx constructor(props) { super(props); this.state = { text: 'Hello Meteorites!', show: true, }; }
  • 26. Conditional Rendering (Checkbox to show text) render() { const { text, show } = this.state; // ... return ( <div id="container"> {/* ... */} {/* Checkbox to show input text box */} <b>Show Input Box:</b> <input type="checkbox" name="showInputBox" checked={show} onChange={this.toggleInputBox.bind(this)} /> <br /><br /> {/* ... */} </div> ); } }
  • 27. Conditional Rendering (Checkbox to show text) // State handler for checkbox toggleInputBox(e) { const show = e.target.checked; this.setState({ show }); }
  • 28. Conditional Rendering (Checkbox to show text) <div id="container"> {/* ... */} {/* Conditionally render input text box based on checkbox value */} { show ? <div> <input type="text" name="updateText" value={text} onChange={this.updateText.bind(this)} /> <br /> </div> : null } {/* ... */} </div> See the Conditional Rendering in action!

Editor's Notes

  • #15: Applications built with React usually have a single root DOM node. To render a React element into a root DOM node, pass both to ReactDOM.render() Now we will see how this is done...