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

An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to MavenVadym Lotar
 
Saving Time By Testing With Jest
Saving Time By Testing With JestSaving Time By Testing With Jest
Saving Time By Testing With JestBen McCormick
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoKnoldus Inc.
 
Python/Flask Presentation
Python/Flask PresentationPython/Flask Presentation
Python/Flask PresentationParag Mujumdar
 
Android Application Development Using Java
Android Application Development Using JavaAndroid Application Development Using Java
Android Application Development Using Javaamaankhan
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial之宇 趙
 
Web application development with Django framework
Web application development with Django frameworkWeb application development with Django framework
Web application development with Django frameworkflapiello
 
Introduction to Django REST Framework, an easy way to build REST framework in...
Introduction to Django REST Framework, an easy way to build REST framework in...Introduction to Django REST Framework, an easy way to build REST framework in...
Introduction to Django REST Framework, an easy way to build REST framework in...Zhe Li
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django IntroductionGanga Ram
 
Spring introduction
Spring introductionSpring introduction
Spring introductionManav Prasad
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - ExplainedSmita Prasad
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture IntroductionHaiqi Chen
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!Jakub Kubrynski
 

What's hot (20)

An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to Maven
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Saving Time By Testing With Jest
Saving Time By Testing With JestSaving Time By Testing With Jest
Saving Time By Testing With Jest
 
Java Entreprise Edition
Java Entreprise EditionJava Entreprise Edition
Java Entreprise Edition
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Python/Flask Presentation
Python/Flask PresentationPython/Flask Presentation
Python/Flask Presentation
 
Android Application Development Using Java
Android Application Development Using JavaAndroid Application Development Using Java
Android Application Development Using Java
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Web application development with Django framework
Web application development with Django frameworkWeb application development with Django framework
Web application development with Django framework
 
Introduction to Django REST Framework, an easy way to build REST framework in...
Introduction to Django REST Framework, an easy way to build REST framework in...Introduction to Django REST Framework, an easy way to build REST framework in...
Introduction to Django REST Framework, an easy way to build REST framework in...
 
A Basic Django Introduction
A Basic Django IntroductionA Basic Django Introduction
A Basic Django Introduction
 
Introduction à Angular 2
Introduction à Angular 2Introduction à Angular 2
Introduction à Angular 2
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
C#.NET
C#.NETC#.NET
C#.NET
 

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
 
Nodejs web service for starters
Nodejs web service for startersNodejs web service for starters
Nodejs web service for startersBruce Li
 

Similar to React Django Presentation (20)

Overview of Node JS
Overview of Node JSOverview of Node JS
Overview of Node 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
 
React native
React nativeReact native
React native
 
Nodejs web service for starters
Nodejs web service for startersNodejs web service for starters
Nodejs web service for starters
 

Recently uploaded

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
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
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
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
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
#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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
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
 
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
 

Recently uploaded (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
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
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
#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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
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
 
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
 

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