React is a JavaScript library the handles the view portion of a single-page Web application.

Using React

React is developed and maintained by Facebook, so we’ll start with their tutorial.

Exercise 8.1

Work through Facebook’s ReactJS tutorial*. Note the following.

Submit this code for Lab 8.

Future labs will extend this basic application in a variety of ways.

Thinking about React

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.

Exercise 8.2

When you’ve worked through the tutorial and have a running application, record your explanations of the following issues.

  1. Explain:

    1. the component structure of the application. What makes the UI composable and why does this matter?
    2. what JSX does.
    3. why ReactJS is safe with respect to XSS.
    4. how the data flows through the components. How are comments loaded? created? saved.
    5. the nature and purpose of props and state. Which is immutable and which is mutable and why does this distinction matter?
  2. Consider the following, more detailed questions based on statements in the tutorial.

    1. Try editing the comments.json file (to add or remove a legal comment). What happens and why?
    2. When the CommentBox has loaded comments from the server (in loadCommentsFromServer()), why doesn’t it call render() to make them visible?
    3. Of what advantage, if any, is it to require that components always represent the current state of the view?
    4. The app implements optimistic updates. Isn’t optimism here more like foolishness? What if the server rejects the new comment (for whatever reason)?

Write brief answers to these questions in lab8_2.txt.

Checking in

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.