sharepoint online – When a document is deleted or published in a document library

I have a requirement to develop a solution based on SPFx, namely, when a document is deleted from a document library or a document is published (got main version) in a document library in SharePoint online, do something? How can I get “notification” or “getChanges” or other opportunity to handle and solve the problem?