13. Managing Data with React Router
Activity 13.1: A To-Dos App
Solution:
Perform the following steps to complete this activity:
- Create a new React project via
npx create-react-app
as explained in Chapter 1, React—What and Why?. Then, install the React Router library by runningnpm install react-router-dom
inside the project folder. Check thepackage.json
file to confirm that you have at least version 6.4 of thereact-router-dom
package installed. - For the three required pages, create three components: a
Todos
component, aNewTodo
component, and aSelectedTodo
component. Store these components in files inside thesrc/routes
folder since these components will only be used for routing. - For the
Todos
component, enter the following code:// src/routes/Todos.js function Todos() { const todos = []; let content = ( <main> <h1>No todos found</h1> ...