skip to Main Content

How can I render the react component once the axios request is completed, I am able to get the data but it shows null twice and then displays the data – Javascript

import "./App.css"; import axios from "axios"; import { useEffect, useState } from "react"; export default function Events() { const [data, setdata] = useState(null); useEffect(() => { axios.get("https://app.ticketmaster.com/discovery/v2/events?apikey=AZAG8m4u5gq5HgkyYk0sdE9eAG32vGPT&locale=*") .then((res) => { setdata(res.data); }) .catch((error) => { console.log("Error encountered", error); }); });…

VIEW QUESTION

How does NextJS execute the code inside these functions with and without async? – Javascript

Function with async: export async function getPostData(id) { const fullPath = path.join(postsDirectory, `${id}.md`); const fileContents = fs.readFileSync(fullPath, 'utf8'); const matterResult = matter(fileContents); return { id, ...matterResult.data, }; } Function without async: export function getPostData(id) { const fullPath = path.join(postsDirectory, `${id}.md`);…

VIEW QUESTION
Back To Top
Search