0

I have encounter a really weird issue in react-native on iOS simulation, the following async function run fine after the first build, if I reload then seems like the await function got frozen. If I deleted the app and rebuild again, then it will run fine

const processPayment = async (amount: number) => {
    console.log("start fetching")

    const data = await new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve({ item: 10 })
      }, 1000)
    })

    console.log(data)
    console.log("end fetching")
  }

console log before reload, can run multiple times

 LOG  start fetching
 LOG  {"item": 10}
 LOG  end fetching

console log after reload

 LOG  start fetching

Calling function

<TouchableOpacity onPress={() => {processPayment(100)}}>
 <Text style={styles.keypad}>PAY</Text>
</TouchableOpacity
DanielNguyen
  • 11
  • 1
  • 2
  • can you also show the code where you are calling processPayment function – adhi narayan Nov 13 '21 at 10:00
  • @adhinarayan I have updated the calling process on the post – DanielNguyen Nov 13 '21 at 10:24
  • is 'reload' a real reload or a hot reload? In a hot reload a lot of static and async functions get problems. If you re-run the app from Xcode it should be no problem. This is not really an issue for the final app as it will not have hot reload mixing up everything. – Christian Nov 13 '21 at 10:31
  • @Christian by reload mean I pressed 'r' on metro window. How would you do a real reload? – DanielNguyen Nov 13 '21 at 10:53
  • @DanielNguyen then I have no idea – Christian Nov 15 '21 at 08:09
  • I have disable the component ToggleStorybook followed suggest from momolafrooo, and the problem seems gone. I should have also mention that I used ignite boilerplate. https://github.com/infinitered/ignite/discussions/1763#discussioncomment-1650294 – DanielNguyen Nov 16 '21 at 10:49

1 Answers1

1

I used ignite boilerplate react native and disable storybook component, the problem seems gone.

DanielNguyen
  • 11
  • 1
  • 2