Normalise a feed and update one entity
The fake API response in the starter gives every post its own copy of its author. Write normalise(posts) so the state is { postsById, usersById, ids }: each post stores authorId instead of an author object, and each user is stored once.
Write the reducer: { type: "rename", userId, name } changes one user; { type: "like", postId } adds 1 to one post's likes.
Render one <article className="post"> per id, in order, containing a <span className="author"> with the author's current name, a <p className="text"> with the text, and a like button with id={"like-" + id} whose text ends with the like count (for example ♥ 3).
Clicking #rename (already in the starter) must update the name on every post by that user.
What Check tests
- Three
.postarticles in the API's order - Each post shows its author's name
- Renaming Asha updates both of her posts and not Ravi's
- Liking p2 adds one to p2 only
- The state is normalised (
usersByIdandauthorId)
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Your page
Console
Nothing logged yet.