5. Class and Function Components
Activity 5.01: Creating a Comments Section
Solution:
- Structuring the app
- Looking at the data, the following structure might work:
App   |-CommentSection     |-Comment
The
CommentSection
component holds all the comments. It shows the heading and has a few associated styles.The
comment
component renders the comment. - Creating the app
In the command line, create the app and navigate to the folder. We can now start running the app by running the
npm start or yarn start
command. Open the folder using your favorite code editor:npx create-react-app comment-app cd comment-app yarn start
- Adding the data file and deleting
src/logo.svg
- Delete
src/logo.svg
and add thesrc/comments.json
file provided in the activity. - Adding the
CommentSection
component insrc/components/CommentSection/index.js
Now, let's create our container component, which will act as a placeholder component for our comments. Since...