Search code examples
javascriptstorybook

How to map a function result to a list if the function is async?


Javascript newbie here. I saw this: https://storybook.js.org/docs/react/configure/overview

// .storybook/main.js

function findStories() {
  // your custom logic returns a list of files
}

module.exports = {
  stories: async (list) => [...list, ...findStories()],
};

And I'm assuming the [...list, ...findStories()] maps an array result from findStories() into list, but how would I get it to work if findStories() was an async function and I needed to await the Promise that findStories() returned? Thanks in advance!


Solution

  • if findStories be an async function you can do it like this:

    module.exports = {
      stories: async (list) => [...list, ...(await findStories())],
    };