A
A
asdasdqwe2022-03-15 12:51:34
typescript
asdasdqwe, 2022-03-15 12:51:34

Property 'value' does not exist on type 'Promise'.?

// api/Category.ts
export function getCategories() {
  return axios
    .get("http://comfort.loc/api/categories/list")
    .then((response) => response.data);
}

this function returns a promise, from there I want to pull out "value"
62306136be9f6120969063.png

// App.tsx
 useEffect(() => {
    let categories = getCategories();
    console.log(categories.value)       // ошибка Property 'value' does not exist on type 'Promise<any>'.
  }, []);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuriy Vorobyov, 2022-03-15
@asdasdqwe

You need to wait for asynchronous code that returns a Promise , use async/await or then() chains

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question