Course Content
React Mastery
React Mastery
1. Introduction to React Fundamentals
What is React?SPAs vs. MPAs in Web DevelopmentHow React Works with the Virtual DOMIntroducing JSX in ReactCreating Complex JSX Elements Rendering Elements in ReactChallenge: Rendering ElementReact ComponentProps in ReactChallenge: Functional ComponentsConditional RenderingChallenge: Conditional Rendering - Chat NotificationChallenge: Conditional Rendering - Bank AlertRendering a Data CollectionChallenge: Rendering a Data CollectionIntroduction to React Section Sum-Up
2. Styling in React Apps
Introduction to Styling in ReactInline StylesInline Styles in PracticeChallenge: Inline StylesStyling with the CSS FileStyling with the CSS File in PracticeChallenge: Styling with the CSS FileStyling with the CSS ModulesFile Folder Structure OrganizationChallenge: CSS ModulesStyling in React Section Sum-Up
3. React Hooks and Context
Introduction: React Hooks and ContextuseState HookChallenge: Toggling VisibilityuseRef HookChallenge: Creating a Form ComponentuseEffect HookChallenge: Fetching and Displaying DatauseMemo HookChallenge: Car List FilteringContextContext in PracticeChallenge: World of Astronomy AppReact Hooks and Context Section Sum Up
Challenge: Conditional Rendering - Chat Notification
Task: Creating Chat Notification
Let's devise a mechanism to display a notification only when a user has unread messages. We will verify whether the user has any unread messages. If this condition is true, we will show a notification indicating the number of messages. However, we won't display anything if the user has no messages.
The task is:
- Create two components:
App
as the parent component andNotification
as the child component. - The parent component,
App
, should pass a prop calledmessages
to the child component. Themessages
prop is an array containing messages. In the child component, you need to check the length of themessages
array. - If there are any messages in the array, display a string that says:
You have <amount> of unread messages.
The<amount>
should be replaced with the actual count of unread messages.
- To determine if there are any messages in the array, we can check its
length
using the length property. The syntax is -array.length
. - In React, we use the operator
&&
to implement the logic of anif
statement. - To construct the string correctly, replace the placeholder
amount
with the actual length of the array. - Use curly braces
{array.length}
to set the array length in the string.
Everything was clear?
Thanks for your feedback!
Section 1. Chapter 12