How to fetch data inside a dynamic component in Next.js 13

41 views Asked by At

I'm trying to fetch dynamic data from an api in Next.js 13 but the fetch function returned nothing.

import axios from "axios";

const baseURL = 'http://127.0.0.1:8000/api/articles/'
const frontURL = 'http://127.0.0.1:3000/'

async function getFeaturedArticles(slug) {

    const response = await axios({
      method: 'GET',
      url: baseURL + slug,
    });
    console(response.data)
    return response.data;
  }

export default function ArticleExpand({params}){
    const article = getFeaturedArticles(params.slug)
    console.log(article)
    return (
        <div>
           <div>
            {article.title}
           </div>
        </div>
    )
}

Neither console(response.data) nor console.log(article) returned something.

0

There are 0 answers