I am a Django developer just getting started with adding React to one page of my app, and really enjoying it so far. (It's a normal Django app with a home page, an about page, etc, but also a "chart" page with an interactive chart, and I want to build the interactive part in React.)
The problem is that I've started with the downloadable React starter kit and I'm not sure how to do things the 'right' way, and it's complicated by using Django to serve my project (all the tutorials seem to assume you're using node, which I'm not).
Right now I just have this in my Django template:
<div id="myapp"></div>
<script src="/static/js/vendor/react.js"></script>
<script src="/static/js/vendor/JSXTransform.js"></script>
<script src="/static/js/myapp.js"></script>
And myapp.js
has all the React code. I'm aware this isn't really the grown-up modern JS way of doing things.
Now I want to use React Bootstrap, but it seems that the only sensible way to do that is with npm
. So it's time to make the switch, but I'm not completely sure how.
I have run npm install react
and npm install react-bootstrap
from inside my static/js
directory in Django. This has created a node_modules
folder with various files inside.
So three questions from a confused newbie:
- Where should I put my React code to work with these npm modules (should I use
var React = require('react')
? - Do I need to compile this code somehow (using
webpack
?) - How do I then integrate this with Django? Should I compile it all to
myapp.js
and just include that in my HTML template?