SlideShare a Scribd company logo
1 of 23
Download to read offline
BLAZOR COMPONENT
LIFECYCLES
INTR ODUC TION
o Component lifecycles refer to all the stages a
certain software component must go through
during its presence
o Each phase holds a significant value and is
executed at certain points in the lifecycle
o In Blazor, these hooks are divided into three main
methods named as Initialization, Rendering,
Updating and Disposal
COMP ONEN T
LIFE CYCL E
BLAZ OR
https://www.google.com/url?sa=i&url=https%3A%2F%2Fjonathancrozier.com%2Fblog%2Funderstanding-the-blazor-component-
lifecycle&psig=AOvVaw0Mrx23NpWb9KR-
M1BCW_SS&ust=1705920176063000&source=images&cd=vfe&opi=89978449&ved=0CBUQjhxqFwoTCODsxIam7oMDFQAAAAAdAAA
AABAD
LIFE CYCL E CO MPON ENTS
o OnInitialized()
o OnInitializedAsync()
o OnParametersSet()
o BuildRenderTree()
o ShouldRender()
o OnAfterRender()
o OnAfterRenderAsync()
o Dispose()
o StateHasChanged()
O N I N I T I A L I Z E D < A S Y N C > ( )
o Executed when the component is created
o It is only executed once (at the time of initialization)
o Useful in the initialization of any component, where
it must be executed no matter what the case is
o It is invoked before the rendering occurs
o OnInitializedAsync is used if the function triggers an
await in the scope
O N I N I T I A L I Z E D < A S Y N C > ( )
The currentCount is
set to 0 and is placed
as a private variable;
O N I N I T I A L I Z E D < A S Y N C > ( )
Clicking this button
will increment the
value by +1
O N I N I T I A L I Z E D < A S Y N C > ( )
Now, let’s set the
value of
currentCount to 5
and place it inside
OnInitialized()
O N I N I T I A L I Z E D < A S Y N C > ( )
Notice that the OnInitialized method
was called the first thing program got
executed. Now, clicking the button
Click me will increment +1 in the
current count
O N P A R A M E T E R S S E T < A S Y N C > ( )
o Executed immediately after OnInitialized<Async> if this is
the new instance of a component
o If it is an existing instance of a component, then it is called
whenever a change has occurred in the component
o Also called when the component’s parameter is set or
changed
o Parameters are properties annotated with the Parameter
attribute. When these parameters change, then
OnParametersSet is invoked
O N P A R A M E T E R S S E T < A S Y N C > ( )
This is the default Index.razor file
which loads initially when the Blazor
Server project is loaded
We called a Counter.razor (child) in
the Index.razor (parent) along with
the certain parameter childCount
whilst setting its value 5
O N P A R A M E T E R S S E T < A S Y N C > ( )
[Parameter] is used to pass the value
childCount from the child to the parent
Index.razor
Sets the parameter value to the currentCount
which is the part of the child
O N P A R A M E T E R S S E T < A S Y N C > ( )
B U I L D R E N D E R T R E E ( )
o Most crucial when it comes to constructing the virtual DOM
representation of the document.
o Virtual DOM refers to the in-memory representation of the
actual HTML structure
o Defines the structure of component’s render tree
o Adds the element, content and attributes
o Takes one parameter i.e., RenderTreeBuilder
S H O U L D R E N D E R ( )
o Allows you to control whether the component should re-
render or not
o Returns only two values true or false
o Inside ShouldRender(), custom logic is added based on the
current and previous state of the component to decide
whether a re-render is necessary
O N A F T E R R E N D E R < A S Y N C > ( )
o The method gets called after the component has been
rendered in your browser’s DOM
o Used for interacting with HTML element.
o Like getElementById() functionalitiy when we use JavaScript
DOM
o Takes a parameter firstRender indicating whether it is
rendered first time or not
O N A F T E R R E N D E R < A S Y N C > ( )
The program changes the heading Counter
Example’s color to green if value of
currentCount is even and blue is it is odd.
However, the color is black initially
S H O U L D R E N D E R ( )
Only displays the count if it is an even
number
S T A T E H A S C H A N G E D ( )
o Part of the ComponentBase class
o Notifies the Blazor Framework that the state of the
component has changed and that a re-render may be needed
o Used when the changes to the component’s state occur
outside of the normal Blazor event-handling lifecycle
S T A T E H A S C H A N G E D ( )
DISP OSE( )
o It is a part of IDisposable pattern and is used for cleanup
operations when the component is being removed from the
UI
o Allows the developers to release the resources, unsubscribe
from resources, or perform other cleanup tasks
o It’s used typically when a component acquires external
resources such as subscriptions, timers or other objects
needed to be released to prevent memory leaks
DISP OSE( )
THAN K YO U

More Related Content

Similar to #6 | Component Lifecycles | Microsoft Blazor | Sameer Siddiqui

Microcontroller lec 3
Microcontroller  lec 3Microcontroller  lec 3
Microcontroller lec 3Ibrahim Reda
 
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...Andrey Karpov
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 
class based component.pptx
class based component.pptxclass based component.pptx
class based component.pptxsaikatsamanta49
 
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...Sivaranjan Goswami
 
PLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxPLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxvamsiyadav39
 
The Ring programming language version 1.7 book - Part 85 of 196
The Ring programming language version 1.7 book - Part 85 of 196The Ring programming language version 1.7 book - Part 85 of 196
The Ring programming language version 1.7 book - Part 85 of 196Mahmoud Samir Fayed
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cppNilesh Dalvi
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answersQuratulain Naqvi
 
Structure of c
Structure of cStructure of c
Structure of cdevauro
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxAnkitaVerma776806
 
Introduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoIntroduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoMark John Lado, MIT
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5REHAN IJAZ
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...RSathyaPriyaCSEKIOT
 

Similar to #6 | Component Lifecycles | Microsoft Blazor | Sameer Siddiqui (20)

Microcontroller lec 3
Microcontroller  lec 3Microcontroller  lec 3
Microcontroller lec 3
 
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
PVS-Studio and Continuous Integration: TeamCity. Analysis of the Open RollerC...
 
Angular 2 in-1
Angular 2 in-1 Angular 2 in-1
Angular 2 in-1
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
class based component.pptx
class based component.pptxclass based component.pptx
class based component.pptx
 
Operators
OperatorsOperators
Operators
 
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
 
PLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxPLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptx
 
The Ring programming language version 1.7 book - Part 85 of 196
The Ring programming language version 1.7 book - Part 85 of 196The Ring programming language version 1.7 book - Part 85 of 196
The Ring programming language version 1.7 book - Part 85 of 196
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answers
 
SRAVANByCPP
SRAVANByCPPSRAVANByCPP
SRAVANByCPP
 
Structure of c
Structure of cStructure of c
Structure of c
 
basic program
basic programbasic program
basic program
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
 
Introduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoIntroduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John Lado
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
Bw14
Bw14Bw14
Bw14
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
 

Recently uploaded

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

#6 | Component Lifecycles | Microsoft Blazor | Sameer Siddiqui

  • 2. INTR ODUC TION o Component lifecycles refer to all the stages a certain software component must go through during its presence o Each phase holds a significant value and is executed at certain points in the lifecycle o In Blazor, these hooks are divided into three main methods named as Initialization, Rendering, Updating and Disposal
  • 3. COMP ONEN T LIFE CYCL E BLAZ OR https://www.google.com/url?sa=i&url=https%3A%2F%2Fjonathancrozier.com%2Fblog%2Funderstanding-the-blazor-component- lifecycle&psig=AOvVaw0Mrx23NpWb9KR- M1BCW_SS&ust=1705920176063000&source=images&cd=vfe&opi=89978449&ved=0CBUQjhxqFwoTCODsxIam7oMDFQAAAAAdAAA AABAD
  • 4. LIFE CYCL E CO MPON ENTS o OnInitialized() o OnInitializedAsync() o OnParametersSet() o BuildRenderTree() o ShouldRender() o OnAfterRender() o OnAfterRenderAsync() o Dispose() o StateHasChanged()
  • 5. O N I N I T I A L I Z E D < A S Y N C > ( ) o Executed when the component is created o It is only executed once (at the time of initialization) o Useful in the initialization of any component, where it must be executed no matter what the case is o It is invoked before the rendering occurs o OnInitializedAsync is used if the function triggers an await in the scope
  • 6. O N I N I T I A L I Z E D < A S Y N C > ( ) The currentCount is set to 0 and is placed as a private variable;
  • 7. O N I N I T I A L I Z E D < A S Y N C > ( ) Clicking this button will increment the value by +1
  • 8. O N I N I T I A L I Z E D < A S Y N C > ( ) Now, let’s set the value of currentCount to 5 and place it inside OnInitialized()
  • 9. O N I N I T I A L I Z E D < A S Y N C > ( ) Notice that the OnInitialized method was called the first thing program got executed. Now, clicking the button Click me will increment +1 in the current count
  • 10. O N P A R A M E T E R S S E T < A S Y N C > ( ) o Executed immediately after OnInitialized<Async> if this is the new instance of a component o If it is an existing instance of a component, then it is called whenever a change has occurred in the component o Also called when the component’s parameter is set or changed o Parameters are properties annotated with the Parameter attribute. When these parameters change, then OnParametersSet is invoked
  • 11. O N P A R A M E T E R S S E T < A S Y N C > ( ) This is the default Index.razor file which loads initially when the Blazor Server project is loaded We called a Counter.razor (child) in the Index.razor (parent) along with the certain parameter childCount whilst setting its value 5
  • 12. O N P A R A M E T E R S S E T < A S Y N C > ( ) [Parameter] is used to pass the value childCount from the child to the parent Index.razor Sets the parameter value to the currentCount which is the part of the child
  • 13. O N P A R A M E T E R S S E T < A S Y N C > ( )
  • 14. B U I L D R E N D E R T R E E ( ) o Most crucial when it comes to constructing the virtual DOM representation of the document. o Virtual DOM refers to the in-memory representation of the actual HTML structure o Defines the structure of component’s render tree o Adds the element, content and attributes o Takes one parameter i.e., RenderTreeBuilder
  • 15. S H O U L D R E N D E R ( ) o Allows you to control whether the component should re- render or not o Returns only two values true or false o Inside ShouldRender(), custom logic is added based on the current and previous state of the component to decide whether a re-render is necessary
  • 16. O N A F T E R R E N D E R < A S Y N C > ( ) o The method gets called after the component has been rendered in your browser’s DOM o Used for interacting with HTML element. o Like getElementById() functionalitiy when we use JavaScript DOM o Takes a parameter firstRender indicating whether it is rendered first time or not
  • 17. O N A F T E R R E N D E R < A S Y N C > ( ) The program changes the heading Counter Example’s color to green if value of currentCount is even and blue is it is odd. However, the color is black initially
  • 18. S H O U L D R E N D E R ( ) Only displays the count if it is an even number
  • 19. S T A T E H A S C H A N G E D ( ) o Part of the ComponentBase class o Notifies the Blazor Framework that the state of the component has changed and that a re-render may be needed o Used when the changes to the component’s state occur outside of the normal Blazor event-handling lifecycle
  • 20. S T A T E H A S C H A N G E D ( )
  • 21. DISP OSE( ) o It is a part of IDisposable pattern and is used for cleanup operations when the component is being removed from the UI o Allows the developers to release the resources, unsubscribe from resources, or perform other cleanup tasks o It’s used typically when a component acquires external resources such as subscriptions, timers or other objects needed to be released to prevent memory leaks