-
Notifications
You must be signed in to change notification settings - Fork 78
Description
The beginning steps of "A React Project" have been rendered outdated in the 2020 edition of the book, as React Router has moved on to v6 on November 3, 2021. As such, certain parts mentioned will not work anymore, such as:
import {
BrowserRouter as Router,
Switch, // Switch has been changed to "Routes"
Route,
Redirect,
} from "react-router-dom";
On top of that, <Route /> will not work as the provided code in step 02 has it now, even after the name substitution from Switch to Routes. Page will render blank and display this warning in the console:

<Route /> now only supports an element prop, which is incompatible with the current code structure. A name substitution such as render to element will not work either. The following error in console will occur:

The above issue can be remedied if the line
<Route exact path="/" render={() => <Posts posts={posts} />} />
is changed to
<Route exact path="/" element={<Posts posts={posts} />} />
A similar issue as the one just mentioned is present for the block of code responsible for rendering a single post:
<Route
path="/post/:postSlug"
render={(props) => {
const post = posts.find(
(post) => post.slug === props.match.params.postSlug
);
if (post) return <Post post={post} />;
else return <NotFound />;
}}
/>