desko27 / react-call

⚛️ 📡 Call your React components
https://react-call.desko.dev
MIT License
445 stars 7 forks source link

Crash - Promise.withResolvers is not a function (it is undefined) in React Native #11

Closed edvansts closed 1 month ago

edvansts commented 1 month ago

First of all, thank you for your brilliant work with the library 🫶

There's a crash when we call the .call() method in a React Native environment. It seems that the JS engine for React Native does not yet support the Promise.withResolvers method, even in the latest versions.

Here's an Expo Snack demonstrating the issue: https://snack.expo.dev/@matos-ed/biased-indigo-raisins

I was able to work around this by creating a polyfill at the root of the project, but I don't think this is an ideal solution.

// Polyfill

if (typeof Promise.withResolvers === 'undefined') {
  // @ts-expect-error
  Promise.withResolvers = function () {
    let resolve, reject;
    const promise = new Promise((res: any, rej: any) => {
      resolve = res;
      reject = rej;
    });
    return { promise, resolve, reject };
  };
}
desko27 commented 1 month ago

This will land v1.3.0. @edvansts thanks for your contribution!!