The official Microsoft sample is the azure/msal-react library: https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-react/README.md
I believe the two samples you referenced might be third party samples.
If your goal is to use React.js , it is recommended to use a single page application and implement the authorization code flow. The sample I referenced implements this flow, and there are also some great online samples and videos like this one: https://www.youtube.com/watch?v=7oPSL5wWeS0
If the information helped you, please Accept the answer. This will help us and improve discoverability for others in the community who may be researching similar questions.