React is a JavaScript library the handles the view portion of a single-page Web application.
React is developed and maintained by Facebook, so we’ll start with their tutorial.
Work through Facebook’s ReactJS tutorial*. Note the following.
Initialize a new Lab08
directory using code from the
Unit08-React course repo. This
implements everything from the tutorial before the “Your first
component” section.
In general, try to build the example code up by hand rather than by just copying from their repo. Here are some notes on the files you’ll build.
server.js
— You can safely ignore the
other versions of their server for different web servers
(e.g., GoLang, Flask, PHP, ...).
package.json
— Use this as written.comments.json
— There are some default
user comments hard-coded in this JSON file.
public/index.html
— They ask you to write
your JavaScript code here in script tags; we suggest that
you delete the script tag and include your code from a
separate scripts/example.js
.
public/css/base.css
— The repo provides
this stylesheet, but the tutorial, as written, never uses
it. Integrate it so that you can have (slightly) better
formatting and so that you can work with CSS in future labs.
public/scripts/example.js
— Delete their
solution here; you’ll build it up piece by piece.
You should already have your own .gitignore
file.
You should now be able to configure and run a server that serves
up a blank HTML index page and JSON-formatted comments via the
route coded into the server.
Submit this code for Lab 8.
Future labs will extend this basic application in a variety of ways.
There’s quite a bit going on in that tutorial, so it’s worth the time to reflect a bit on how it’s constructed and how it works.
When you’ve worked through the tutorial and have a running application, record your explanations of the following issues.
Explain:
Consider the following, more detailed questions based on statements in the tutorial.
comments.json
file (to add or
remove a legal comment). What happens and why?
loadCommentsFromServer()
), why doesn’t it
call render()
to make them visible?
Write brief answers to these questions in lab8_2.txt
.
We will grade your work according to the following criteria:
*In October, 2016, Facebook replaced their original tutorial (archived here by the Wayback Machine) with this new version. Note that the copy linked above references the new code; the solution for the old tutorial is hosted on our course's GitHub repo.