[Issue 2146] Replace Missing Content in the Optimizing Your React Node Project #2502
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📝 Description
The previous code reference (a Gist) was no longer available. This PR provides a new, self-contained, and minimal Node.js + React (Vite) project that fulfills all the learning objectives of the lesson, focusing on caching strategies and React rendering optimizations.
🔂 Changes Made
npm run build
outputs todist
), and server commands (npm run server
).dist
directory.React.memo
for functional components.npm run build
outputs todist
), and server commands (npm run server
).dist
directory.React.memo
for functional components.⚙️ Related Issue
Issue Number: #2146
🍏 Type of Change
🎁 Acceptance Criteria
npm run build
without errors.npm run dev
(onhttp://localhost:3000
).npm run server
(onhttp://localhost:3001
).EventfulSearch
works as expected.eventful-api-server.js
is observable (initial delay, then faster responses).EventCard
component logs its re-renders to the console.EventCard
is replaced withOptimizedEventCard
inEventfulSearch.tsx
, the console logs demonstrate reduced re-renders for unchanged components.🧪 How to test or what to evaluate
npm install
.npm run server
.npm run dev
.http://localhost:3000
.source: "api"
in the search info.source: "server-cache"
is indicated.source: "client-cache"
is indicated.console.log
messages fromEventCard
indicating each card's render.src/components/EventfulSearch.tsx
:OptimizedEventCard
at the top:import OptimizedEventCard from "./OptimizedEventCard";
<EventCard key={event.id} event={event} />
with<OptimizedEventCard key={event.id} event={event} />
.console.log
messages. You should see fewer re-renders forOptimizedEventCard
compared toEventCard
when the props haven't changed (e.g., if you search for the same thing multiple times, only the first render should log for each card).npm run build
.dist/
directory in the project root.npm run preview
to serve the production build and verify it functions correctly.dist
instead ofbuild
,server/eventful-api-server.js
), and explanations align with the new code.