Conteúdo do Curso
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 - Bank Alert
Task: Creating a Bank Alert
Let's work with a bank account. We aim to develop a logic that informs the user whether they have sufficient funds on their card to cover a given price. Depending on the outcome, we will display different messages to the user.
The task is:
- Create two components -
App
, parent, andMessage
, child. - The parent component (
App
) transfers the propsmoneyAvailable
,price
, andname
.moneyAvailable
- represents the amount of money the user has;price
- denotes the amount of money the user needs to pay;name
- refers to the user's name.
- If the user has enough money to pay, we show the message:
Success! The remaining amount of money for <user_name> is: <calculated_amount_of_money_left>. Thank you!
. - If the user has not enough money to pay, we show the message:
Failure! The bank account balance for <user_name> is: <moneyAvailable>. Unfortunately, you need to pay: <price>.
- In React, we use the ternary operator
condition ? ... : ...
to implement the logic of anif...else
statement. - To construct the string correctly,
- Replace the placeholder
user_name
with the actual user name:name
prop; - Replace the placeholder
calculated_amount_of_money_left
with the calculated amount of money left -moneyAvailable - price
; - Replace the placeholder
moneyAvailable
with the actual available money -moneyAvailable
prop; - Replace the placeholder
price
with the actual price -price
prop.
- Replace the placeholder
- Use curly braces
{...}
to assign a value that is not a string type.
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 1. Capítulo 13