![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
ES7 async/await
gives to developers ability to write asynchronous code that look like synchronous. But under the hood it is still just a sugar on top of the ES6 Promise
.
You can write code that looks clean, but only unless you have to catch errors. To catch thrown error or handle the promise's rejection you have to surround it with try-catch
block or fallback to pure promises and from that moment visual purity of your code is over.
But there is a solution!☀️
I really like the way it's done in Go. It has no error throwing mechanism, but has a multi-value return and the common way to handle errors in Go is to return error as a last value, like so:
data, err := someErrorFunc(someStuff)
if err != nil {
return err
}
But JavaScript has no multi-value return! - you would say. Sad, but true.
But!
It has a destructuring assignment and await-of
gives you ability to do this:
import { of } from "await-of";
async () => {
let [res, err] = await of(axios.get("some.uri/to/get"));
if (err) {
// rethrow if its not an axios response error
if (!err.response) {
throw err;
}
res = err.response;
}
const { data, status = 0 } = res;
console.log(data, status);
};
There is no modifications needed in function/promise you want to await - just pass it to the of()
and whole the magic will be done.
npm i --save await-of
import { of } from "await-of";
async function someAsyncStuff() {
let error, data;
// if we don't want to handle error
[data] = await of(Promise.reject(new Error("ERROR!")));
console.log(data); // undefined
// if promise was rejected - it's rejection value will be treated as error
[, error] = await of(Promise.reject(new Error("ERROR!")));
console.log(error); // ERROR!
// or if promise has any uncaught errors it'll catch them too!
[, error] = await of(
new Promise(() => {
throw new TypeError("ERROR!");
})
);
console.log(error.message); // ERROR!
}
# install dependencies if you haven't yet
npm install
npm run test
FAQs
await wrapper for easier errors handling without try-catch
The npm package await-of receives a total of 0 weekly downloads. As such, await-of popularity was classified as not popular.
We found that await-of demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.