简体   繁体   中英

how to destructure nested data from reactQuery/useQuery in next.js/react.js

const {
  isLoading,
  data: products,
  refetch,
} = useQuery(["products"], () =>
  axios.get(
    `https://product-bazar.herokuapp.com/api/v1/public/product`
  )
);

How can I destruct data from data in this query operations ex:[data?.products]

You can destruct the nested data from response data. example given below:

const { isLoading, data: products, refetch, } = useQuery(["products"], () => axios.get( https://product-bazar.herokuapp.com/api/v1/public/product ).then((res) => res.data?.products));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM