Detect SharePoint environment type and page mode from an SPFx web part
Knowing the SharePoint environment and if the page is edit mode will allow you to provide tailored web parts to enhance the user experience of your SharePoint solutions.
The code provided in this article gives you the ability to detect if your SPFx web part is running in the modern or classic SharePoint environment and if the page is in edit mode.