-1

How can I access to a variable outside function next.js i want to get name outside the data

let getDetail = async () => {
    let body = { 
      code: '12',
      provider: 'bb', 
      
    };
     let { data } = await Axios.post(
      "https://blbla",
      JSON.stringify(body)
    );   
      let { name } = data;
      
  };
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 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) – jonrsharpe Jul 09 '20 at 18:37

1 Answers1

0

You could return name,

let { name } = data;
return name;

and then when you call the function, if you need the name, you could say:

name = getDetail();
Daniel
  • 1,392
  • 1
  • 5
  • 16