DJANGO MEETUP
Integrating React in
Django while staying
sane and happy
What is this React
thing anyway?
REACTJS.ORG
“React is a declarative, efficient,
and flexible JavaScript library for
building user interfaces.”
• Clean code – Complex and reactive frontends usually
produce complex code
• Fewer frontend bugs with Unit and Snapshot Tests
• Frontend developer experience is great
• Frontend developers do not need to know the
underlying backend
Why do I want this in my project?
How do I integrate
it in Django?
There are a few ways
to do this...
• Leads to a scattered codebase – Hard to navigate
• Developers must jump between DTL and React
Only using React for some
components
• Hard work to keep routing in sync between frontend/
backend-app
• Might have to reimplement much functionality that
already exists in Django or 3d party apps
Everything in React including
routing (SPA)
• Clear project structure
• Can still use Django and 3d party apps without too
much hazel
Let React handle the frontend,
let Django handle requests and routing
Let´s look at code! 🎉
Django implementation:
Template
https://github.com/Frojd/django-react-templatetags
Django implementation:
Views
React implementation
Client Side Rendering
• Slow initial page load
• Page flicker on navigation
• Does not work without JS
Server Side Rendering (SSR)
https://github.com/Frojd/Hastur/
• Running as a node daemon
• Integrates with Django-react-templatetags
So... Is there any cons?
• JS bundle file size
• Be careful when installing javascript libraries
• Analyze your javascript bundle with webpack-bundle-analyzer
• Preact or other framework
• Server Side Rendering require another service running
Cons
• https://github.com/mikaelengstrom/django-react-polls-example
• https://github.com/Frojd/django-react-templatetags/
• https://github.com/Frojd/Hastur/
• https://github.com/Frojd/react-sass-starterkit
• http://www.django-rest-framework.org/
• https://www.npmjs.com/package/webpack-bundle-analyzer
Links
¿Questions? 🤔
SOCIAL MEDIA OFFICECONTACT
Thanks
Mikael Engström
mikael.engstrom@frojd.se
Twitter: @FrojdAgency
Facebook: @FrojdAgency
Linkedin: Fröjd Agency
Fröjd Interactive AB
Kungstensgatan 18
113 57 Stockholm

Integrating react in django while staying sane and happy