Home > Blockchain >  I want to save the axios.post request in a const and return that const in the function
I want to save the axios.post request in a const and return that const in the function

Time:12-24

export async function getCategories() {
  const https = "xxxxxx";
  const url = `${https}/api/Category/GetCategories`;

  const userToken ="xxxxxxxx"

  const authStr = "Bearer ".concat(userToken);

  const options = {
    method: "POST",
    headers: {
      Authorization: authStr,
    },
    url: url,
  };

  const response = await axios(options)
    .then((response) => console.log(response.data[0].categoryName))
    .catch((error) => console.log(error.toJSON()));

  const fetchedCategories = response.data[0];
  console.log(
    "           
  • Related