1

Someone told me that he was using componentDidMount and componentDidUpdate in his BaseWebPart class, but looking at the documentation below I realized it shouldn't be possible since it's not a React Component.

BaseWebPart class

Is there something I am missing, what do you need to do in order to be able to use componentDidMount and componentDidUpdate? Or is it possible that there was some kind of misunderstanding and he did not use componentDidMount and componentDidUpdate in his BaseWebPart class. Is it also best practice to use componentDidMount and componentDidUpdate instead of the onInit provided by the BaseWebPart class.

2

BaseWebPart class is something comes with @microsoft/sp-webpart-base package and componentDidMount & componentDidUpdate are methods of The Component Lifecycle of React.

These are not related at all. So, you cannot write componentDidMount & componentDidUpdate methods in BaseWebPart class.

However if you want to use the React components in your SPFx webpart then you need to import the dependencies. Check below documentation on how to use it:

HOW TO GET STARTED WITH REACT FOR BUILDING ADVANCED SPFX SOLUTIONS.

2

You are right. It is not possible, nor wanted to use any React component lifecycle in BaseWebPart.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.