Home > Mobile >  What's the best practice around exporting an async value in JavaScript?
What's the best practice around exporting an async value in JavaScript?

Time:05-03

In the code snippet below, I'm trying to export a value that relies on async operations. Is this the best way to do that? It just feels a bit weird.

I'd love any suggestions! Thanks!

import ohm from "ohm-js";

export default await (async () => {
  let response = await fetch("./grammar.ohm");
  let source = await response.text();
  return ohm.grammar(source);
})();

CodePudding user response:

You don't need the async IIFE:

import ohm from "ohm-js";

let response = await fetch("./grammar.ohm");
let source = await response.text();
export default await ohm.grammar(source);
  • Related