SlideShare a Scribd company logo
1 of 31
z
ReactJS +
Django
How to Reactify
Your App
Alli DiNapoli
z
Why React?
 In my humble opinion, it’s a lot easier to learn than vanilla
javascript, and it’s definitely a lot easier to read
 React is incredibly efficient
 It uses a Virtual DOM stored in memory. It compares the updated
Virtual DOM with the previous version, and calculates the minimum
number of updates necessary to update the DOM.
 It’s great for SEO
 Great Developer tools
 It’s responsive
 I could honestly continue for ages here
z
But I already have Django templates!
 Components are more decoupled, isolated, and
testable than templates
 Django templates tend to fall short when trying to
manage complex state in the browser
 jQuery used to be the standard tool to use with
Django to add interactivity, but as single page web
apps become standard, maintaining intricate jQuery
logic isn’t the best practice anymore
z
Basic React Vocabulary
 Components
 Components let you split the UI into independent, reusable pieces, and
think about each piece in isolation (source)
 They are displayed like html elements <Example />
 Properties
 Properties are inputs and should remain constant
 <Example property1={value} />
 States
 States are initialized in the constructor and are meant to change over time
 They determine how the component renders and behaves
 The state is updated by calling this.setState({name:value})
z
zz
Tools
These are going to be
our main players while
adding React into our
Django application.
z
What about existing jQuery?
 Adding another library (ie, jQuery) adds a significant amount of
overhead to the application, impacting the load for users
 Everything that can be accomplished with jQuery can be done
easily with react, or just plain Javascript
 React is unaware of the changes made to the DOM outside of
React
 If you really need it, there are lightweight alternatives such as
minifield.js and Zepto.js that use a similar syntax
 Conclusion:
z
Burn it. Burn it with fire.
z
So let’s get started with React!
z
First things first, install NodeJS and npm
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash
sudo apt-get install -y nodejs
• NodeJS is a javascript library, and npm is the package manager for NodeJS.
• npm will be used to pull various libraries (such as react) and to help build our javascript files
from the React jsx syntax
z
npm init
• Creates
package.json
• You can enter in
the default values
for all of these.
z
Install Webpack with npm
npm install webpack webpack-bundle-tracker --save-dev
• This is the basic syntax for installing a package from npm
• --save-dev and --save place the file in package.json
• This is incredibly important to use, because it keeps track of
your dependencies.
• When pulling code from git, you can run npm install and it
will automatically install all packages in package.json
• We’ll look at the structure of package.json in a little bit
z
Create webpack.config.js
• Take note of
entry and output
• You can have
multiple entries
z
package.json
• This is all
automatically
generated from the
npm init except for
the build value in
scripts
• Add this to compile
your react on the
command
npm run build
• SPOILER ALERT!
• There are
packages here
that haven’t been
installed yet
z
Install Babel and create a .babelrc file
npm install babel-loader babel-core babel-preset-es2015 babel-preset-react --save-dev
/*
./.babelrc
*/
{
“presets”:[
“es2015”, “react”
]
}
z
Now let’s finally install react
npm install react react-dom --save-dev
z
Where to put react code?
• My personal recommendation is to have a separate folder for your
react code but you can organize it however you wish
• I would not recommend placing it in your static folder, but it’s not
compiled and ready for the browser yet
z
Django Template
• This is an incredibly
basic template just
as an example
• We add a span (or
div) with a unique
label wherever we
want our react
components to go
z
index.js - React
• This file will be where we place our components on the page
• I’m just using a div as an example to test – we’ll get to react components in a second
z
npm run build
• Remember adding the build script
to package.json? This is where
that comes into use.
• It uses webpack to compile with
babel and places the compiled
javascript into the static folder as
specified in the webpack config
z
It works!
So responsive! Viewable on any browser!
z
Adding React Components
 Within the react directory, we’ll create a new directory
called components.
 In this directory we can create different components
that can be easily placed into our webapp from the
index.js file
z
Adding React Components
 This is the syntax for a very basic react component
 States, props (properties), and plain javascript functions can be
added as needed
z
Our new index.js
z
Wow. So breathtaking. Very beautiful
z
Leveling up our react components
 There are a TON of open-source libraries to help with creating
attractive components, or you can create your own!
 I’ll give a quick example using material-ui, Goggle’s material design
npm install material-ui --save
z
Material UI
part 1
z
Material UI
part2
z
Consider this app… reactified
z
Additional Notes
 Make sure your static files are set up properly in settings.py
(here’s what mine look like)
 There is a really nice browser extension in Chrome and Firefox
that allows you to debug react with developer tools
 Passing data from Django to React can be done either with an
API or with global js variables set inside a <script> element in
the template where the react component is placed.
 https://github.com/allison-dinapoli/react-django-tutorial
z
Conclusions!
 React and Django are the perfect combination!
 Integrating React into Django requires a few tools, but once set
up it is very easy to maintain and build up.
 Using React with Django adds a whole new library of open
source code to help you build your app (ie material-ui)
z
Fin.
Questions? Comments? REACTions?

More Related Content

What's hot

Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JSArno Lordkronos
 
React js programming concept
React js programming conceptReact js programming concept
React js programming conceptTariqul islam
 
Gaganjot Kaur- The Nx Workspace.docx
Gaganjot Kaur- The Nx Workspace.docxGaganjot Kaur- The Nx Workspace.docx
Gaganjot Kaur- The Nx Workspace.docxGaganjot kaur
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentationThanh Tuong
 
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Edureka!
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoAhmed Salama
 
Getting Started with React.js
Getting Started with React.jsGetting Started with React.js
Getting Started with React.jsSmile Gupta
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
Building an API with Django and Django REST Framework
Building an API with Django and Django REST FrameworkBuilding an API with Django and Django REST Framework
Building an API with Django and Django REST FrameworkChristopher Foresman
 
Introduction to back-end
Introduction to back-endIntroduction to back-end
Introduction to back-endMosaab Ehab
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for BeginnersJason Davies
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 

What's hot (20)

Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
Gaganjot Kaur- The Nx Workspace.docx
Gaganjot Kaur- The Nx Workspace.docxGaganjot Kaur- The Nx Workspace.docx
Gaganjot Kaur- The Nx Workspace.docx
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
Django Seminar
Django SeminarDjango Seminar
Django Seminar
 
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Getting Started with React.js
Getting Started with React.jsGetting Started with React.js
Getting Started with React.js
 
Pengenalan ReactJS
Pengenalan ReactJS Pengenalan ReactJS
Pengenalan ReactJS
 
Vue JS Intro
Vue JS IntroVue JS Intro
Vue JS Intro
 
React
ReactReact
React
 
Spring boot
Spring bootSpring boot
Spring boot
 
React js
React jsReact js
React js
 
Building an API with Django and Django REST Framework
Building an API with Django and Django REST FrameworkBuilding an API with Django and Django REST Framework
Building an API with Django and Django REST Framework
 
Svelte as a Reactive Web Framework
Svelte as a Reactive Web FrameworkSvelte as a Reactive Web Framework
Svelte as a Reactive Web Framework
 
Introduction to back-end
Introduction to back-endIntroduction to back-end
Introduction to back-end
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for Beginners
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 

Similar to React Django Presentation

Overview of Node JS
Overview of Node JSOverview of Node JS
Overview of Node JSJacob Nelson
 
Getting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperGetting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperFabrit Global
 
Create ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm packageCreate ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm packageAndrii Lundiak
 
Learn reactjs, how to code with example and general understanding thinkwik
Learn reactjs, how to code with example and general understanding   thinkwikLearn reactjs, how to code with example and general understanding   thinkwik
Learn reactjs, how to code with example and general understanding thinkwikHetaxi patel
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]GDSC UofT Mississauga
 
The complete-beginners-guide-to-react dyrr
The complete-beginners-guide-to-react dyrrThe complete-beginners-guide-to-react dyrr
The complete-beginners-guide-to-react dyrrAfreenK
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)Chiew Carol
 
Using React with Grails 3
Using React with Grails 3Using React with Grails 3
Using React with Grails 3Zachary Klein
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1MD Sayem Ahmed
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppEdureka!
 
Maven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsSteve Keener
 
Front-End Modernization for Mortals
Front-End Modernization for MortalsFront-End Modernization for Mortals
Front-End Modernization for Mortalscgack
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernizationdevObjective
 
Lecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptxLecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptxGevitaChinnaiah
 

Similar to React Django Presentation (20)

Overview of Node JS
Overview of Node JSOverview of Node JS
Overview of Node JS
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
Getting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular DeveloperGetting Started with React, When You’re an Angular Developer
Getting Started with React, When You’re an Angular Developer
 
Create ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm packageCreate ReactJS Component & publish as npm package
Create ReactJS Component & publish as npm package
 
Learn reactjs, how to code with example and general understanding thinkwik
Learn reactjs, how to code with example and general understanding   thinkwikLearn reactjs, how to code with example and general understanding   thinkwik
Learn reactjs, how to code with example and general understanding thinkwik
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 
The complete-beginners-guide-to-react dyrr
The complete-beginners-guide-to-react dyrrThe complete-beginners-guide-to-react dyrr
The complete-beginners-guide-to-react dyrr
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
 
Using React with Grails 3
Using React with Grails 3Using React with Grails 3
Using React with Grails 3
 
Reactjs
ReactjsReactjs
Reactjs
 
An Introduction to Maven Part 1
An Introduction to Maven Part 1An Introduction to Maven Part 1
An Introduction to Maven Part 1
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web App
 
Django Girls Tutorial
Django Girls TutorialDjango Girls Tutorial
Django Girls Tutorial
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
 
Maven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable ResultsMaven: Managing Software Projects for Repeatable Results
Maven: Managing Software Projects for Repeatable Results
 
Front-End Modernization for Mortals
Front-End Modernization for MortalsFront-End Modernization for Mortals
Front-End Modernization for Mortals
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernization
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernization
 
Lecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptxLecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptx
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 

Recently uploaded

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 

Recently uploaded (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 

React Django Presentation

  • 1. z ReactJS + Django How to Reactify Your App Alli DiNapoli
  • 2. z Why React?  In my humble opinion, it’s a lot easier to learn than vanilla javascript, and it’s definitely a lot easier to read  React is incredibly efficient  It uses a Virtual DOM stored in memory. It compares the updated Virtual DOM with the previous version, and calculates the minimum number of updates necessary to update the DOM.  It’s great for SEO  Great Developer tools  It’s responsive  I could honestly continue for ages here
  • 3. z But I already have Django templates!  Components are more decoupled, isolated, and testable than templates  Django templates tend to fall short when trying to manage complex state in the browser  jQuery used to be the standard tool to use with Django to add interactivity, but as single page web apps become standard, maintaining intricate jQuery logic isn’t the best practice anymore
  • 4. z Basic React Vocabulary  Components  Components let you split the UI into independent, reusable pieces, and think about each piece in isolation (source)  They are displayed like html elements <Example />  Properties  Properties are inputs and should remain constant  <Example property1={value} />  States  States are initialized in the constructor and are meant to change over time  They determine how the component renders and behaves  The state is updated by calling this.setState({name:value})
  • 5. z zz Tools These are going to be our main players while adding React into our Django application.
  • 6. z What about existing jQuery?  Adding another library (ie, jQuery) adds a significant amount of overhead to the application, impacting the load for users  Everything that can be accomplished with jQuery can be done easily with react, or just plain Javascript  React is unaware of the changes made to the DOM outside of React  If you really need it, there are lightweight alternatives such as minifield.js and Zepto.js that use a similar syntax  Conclusion:
  • 7. z Burn it. Burn it with fire.
  • 8. z So let’s get started with React!
  • 9. z First things first, install NodeJS and npm curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash sudo apt-get install -y nodejs • NodeJS is a javascript library, and npm is the package manager for NodeJS. • npm will be used to pull various libraries (such as react) and to help build our javascript files from the React jsx syntax
  • 10. z npm init • Creates package.json • You can enter in the default values for all of these.
  • 11. z Install Webpack with npm npm install webpack webpack-bundle-tracker --save-dev • This is the basic syntax for installing a package from npm • --save-dev and --save place the file in package.json • This is incredibly important to use, because it keeps track of your dependencies. • When pulling code from git, you can run npm install and it will automatically install all packages in package.json • We’ll look at the structure of package.json in a little bit
  • 12. z Create webpack.config.js • Take note of entry and output • You can have multiple entries
  • 13. z package.json • This is all automatically generated from the npm init except for the build value in scripts • Add this to compile your react on the command npm run build • SPOILER ALERT! • There are packages here that haven’t been installed yet
  • 14. z Install Babel and create a .babelrc file npm install babel-loader babel-core babel-preset-es2015 babel-preset-react --save-dev /* ./.babelrc */ { “presets”:[ “es2015”, “react” ] }
  • 15. z Now let’s finally install react npm install react react-dom --save-dev
  • 16. z Where to put react code? • My personal recommendation is to have a separate folder for your react code but you can organize it however you wish • I would not recommend placing it in your static folder, but it’s not compiled and ready for the browser yet
  • 17. z Django Template • This is an incredibly basic template just as an example • We add a span (or div) with a unique label wherever we want our react components to go
  • 18. z index.js - React • This file will be where we place our components on the page • I’m just using a div as an example to test – we’ll get to react components in a second
  • 19. z npm run build • Remember adding the build script to package.json? This is where that comes into use. • It uses webpack to compile with babel and places the compiled javascript into the static folder as specified in the webpack config
  • 20. z It works! So responsive! Viewable on any browser!
  • 21. z Adding React Components  Within the react directory, we’ll create a new directory called components.  In this directory we can create different components that can be easily placed into our webapp from the index.js file
  • 22. z Adding React Components  This is the syntax for a very basic react component  States, props (properties), and plain javascript functions can be added as needed
  • 24. z Wow. So breathtaking. Very beautiful
  • 25. z Leveling up our react components  There are a TON of open-source libraries to help with creating attractive components, or you can create your own!  I’ll give a quick example using material-ui, Goggle’s material design npm install material-ui --save
  • 29. z Additional Notes  Make sure your static files are set up properly in settings.py (here’s what mine look like)  There is a really nice browser extension in Chrome and Firefox that allows you to debug react with developer tools  Passing data from Django to React can be done either with an API or with global js variables set inside a <script> element in the template where the react component is placed.  https://github.com/allison-dinapoli/react-django-tutorial
  • 30. z Conclusions!  React and Django are the perfect combination!  Integrating React into Django requires a few tools, but once set up it is very easy to maintain and build up.  Using React with Django adds a whole new library of open source code to help you build your app (ie material-ui)

Editor's Notes

  1. I can’t wait to hear your…. REACTIONS after this talk (probably don’t actually say that) (or maybe do)
  2. Talk about looking at someone else’s messy javascript jquery code and literally wanting to die (don’t actually say that) trying to understand it. Talk about how much easier it is to read and parse react code. v nice to read Search engines often have a hard time reading javascript-heavy applications, but not with react!
  3. These are the tools we will use!!! :D
  4. Maybe make a funny comment about just wanting to include this gif? While it is possible to integrate react with existing jQuery, my recommendation would be to not. Just give it up. All hope is lost. jk But for real, it’s a lot of overhead to try and integrate it, and can get unnecessarily complex. It’s much easier to replace it with react than it is to try and slowly integrate it. I’ve heard of people converting all jQuery to vanilla javascript and then adding in react… you can do this if you don’t have a huge amount of jQuery, or you can try and slowly add it piece by piece while removing jQuery as you go… but that can get difficult as well if you have a lot of jQuery. It’s not going to be fun, but it is going to be worth it.
  5. run npm init in the same directory that contains your manage.py or don’t, but I find it easier to run everything from one directory instead of jumping around. also all javascript and react should be in sub directories from this
  6. Your entry is going to be the react file or files that will be compiled into javascript using webpack and babel Your output is going to be the static javascript files that are created from it, you should place these in your static directory Note that this should be in the same directory as your package.json
  7. babel is a javascript compiler. this enables babel to compile to ES6 and React
  8. don’t forget to npm run build
  9. Hard-coding is my passion jk this is just for the tutorial realistically you would have a database with this info but #rip Look at all this code! Point out how we’re setting variables in the render function that’s cool! gloss over states
  10. Django lets us have a very intricate backend while maintaining the best possible front end. It’s interactive and amaze