Aug 22, 2024
react-router-dom
for routing.npm i react-router-dom
.BrowserRouter
as Router
in app.jsx
.navbar.jsx
.react-router-dom
.NavBar
: Links to a post list and a new post form.NavBar
at the end.PostList
with AppRoutes
component.AppRoutes
from components.appRoutes.jsx
, import Routes and Route from react-router-dom
./
for PostList
./new
for a new post form./posts/:id
for PostDetails
.AppRoutes
.postDetails.jsx
in the posts directory.useState
, useParams
from react-router-dom
.PostDetails
: Fetches and displays individual post details.useEffect
to fetch post details on component mount and when ID changes.fetchCurrentPost
: Uses fetch
to get post data by ID.console.log
in a catch
block.loading
state to handle asynchronous fetch delays.