Command Palette

Search for a command to run...

Hectal
Phase 26: Interview Deep Dives
React · Exercise 6 of 6 Previous
Advanced

Nested comments with replies

Timed build (30 minutes). Render the initial comments with their replies at any depth. Each comment is an <li className="comment"> containing a <p className="text"> with Author: text, a <button className="reply">Reply</button>, and, when it has replies, a nested <ul> of comments inside the same li.

Clicking Reply shows a <form> inside that comment with an <input> and a submit button. Submitting adds a reply from author You under that comment (trim the text, ignore empty replies) and closes the form.

A paragraph id="total" shows the number of comments at every depth, like 3 comments. Compute it from the tree; don't store it.

What Check tests

  1. All three comments render and the total says 3 comments
  2. Ravi's reply is nested inside Asha's comment
  3. Replying to Ravi adds a nested reply from You
  4. The total updates to 4 comments
  5. An empty reply is ignored
  6. Replying to a top-level comment works too

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.