SPFx Basics: Initializing components - constructor vs. onInit()

Опубликовано: 22 Февраль 2022
на канале: Andrew Connell
629
15

In this #SharePoint Framework (#SPFx) basics post, I want to focus on a question I commonly see pop up in forums as well as with new and experienced students of our SPFx course. This applies to every type of SPFx component that developers can create, including web parts, all types of extensions, libraries, and Adaptive Card Extensions (ACEs).

🙋♂️ How do you properly initialize your component? Should you use the object’s constructor or the onInit() method?

👉 You should always use the onInit() method if your initialization process needs anything in the SharePoint Framework API or in the current page’s context. Otherwise, you can safely use the constructor in your component.

Why? 🤷♂️

In this post, I explain why, and what’s happening under the covers, and consider a real-world example.

This video is also available as a blog post and our podcast as episode 006 via the following links:
📜 https://www.voitanos.io/blog/initiali...
🎙 https://www.voitanos.io/podcast


🎧 Chapters / Show Notes
-------------------------------------------
00:00 : Intro
03:31 : Exploring the SPFx page lifecycle
09:08 : Real-world example: constructor vs. onInit()


🔗 Links
---------------
🌎 https://www.voitanos.io
🎙 Podcast: https://www.voitanos.io/podcast
  / andrewconnell  
  / voitanos  
  / andrewconnell  
  / voitanos_llc  

#sharepointframework


На этой странице сайта вы можете посмотреть видео онлайн SPFx Basics: Initializing components - constructor vs. onInit() длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Andrew Connell 22 Февраль 2022, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 629 раз и оно понравилось 15 зрителям. Приятного просмотра!