Since script editor is not available in SharePoint for Microsoft 365 modern pages. You will need to use SharePoint Framework to custom your web part. Please refer to following document
Where are the Content editor and Script editor web parts in SharePoint?
You can build the SPFx solution package from https://github.com/pnp/sp-dev-fx-webparts/tree/master/samples/react-script-editor.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.