Promises are running twice in reactjs [closed]

I have created a simple promise and when I call then on it, the promise is running twice.

import React from 'react'

function App() {

  let promise = new Promise(function (resolve, reject) {
    resolve("hello")
  })

  promise.then(function (res) {
    console.log(res)
  })
  return (
    <>
      Hello
    </>
  )
}

export default App

When I visit localhost:3000, and open debugger it shows “hello” printed twice. I am not able to understand what is going on. Please help

Answer

If you are using create-react-app, it’s likely that your App is wrapped with StrictMode which causes an additional render of your App. Check your app’s index.js.