0

I have the following code:

export const getTagsByType = <Data extends { keywords?: { tags: { name: string, type: string }[] } }>(type: string, rawData: Data) => {
    return rawData.keywords?.tags.filter((tag) => tag.type === type).map(tag => tag.name);
}


export const buildLoadedData = () => {
    const rawDTMData = window.DATA;

    return {
        "loaded_content":getTagsByType("generic", rawDTMData).toString(),
        
    }
}

However, buildLoadedData returns before the function executes for some reason. What do I do here so that loaded_content actually has some content?

Elemental
  • 13
  • 2
  • 1
    my guess is that is not your exact code or `window.DATA` does not have what you think it has at that moment in time. – epascarello Oct 21 '22 at 17:21
  • Does this answer your question? [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – devlin carnate Oct 21 '22 at 17:40
  • @devlincarnate There is no async call in that code. – epascarello Oct 21 '22 at 17:40
  • @epascarello - but isn't the solution the same to what the OP is looking for? – devlin carnate Oct 21 '22 at 17:41
  • 1
    @devlincarnate The problem is not in the code the OP shared. There is not a single async call in it. – epascarello Oct 21 '22 at 18:34
  • @epascarello - but if the linked duplicate provides a solution to the OP's question, it's a valid duplicate. There is no requirement that the questions themselves are the same. The OP needs to have a function wait for another function to return. That duplicate provides a solution for what the OP needs. – devlin carnate Oct 21 '22 at 18:42
  • 1
    @devlincarnate WHERE is the asynchronous code in OPs code. Where? :) I would agree with you if there was asynchronous code, but filter and map is not async. The problem is not in the code that is provided. – epascarello Oct 21 '22 at 19:22

0 Answers0