1

how to solve the problem Promise { <pending> }

I'm new in next JS, when I am trying to display my data in a particular route , its not showing , can anyone tell me why its not showing, if you have any query regarding my question please free fell to ask.

Pending Promises

import { getDataFromSheets } from "../../libs/sheets";

export default function handler(req, res) {

    const sheet =  getDataFromSheets();

    console.log(sheet)

    res.status(200).json(sheet);

}

Submitted October 10th 2021 by Admin

Answers
0

Use async/await

import { getDataFromSheets } from "../../libs/sheets"; export default async function handler(req, res) { const sheet = await getDataFromSheets(); console.log(sheet) res.status(200).json(sheet); }

Admin | 1 week ago


0

Use can solve this in a couple of ways,

Using async/await

import { getDataFromSheets } from "../../libs/sheets"; export default async function handler(req, res) { const sheet = await getDataFromSheets(); console.log(sheet) res.status(200).json(sheet);
}

Using .then(), .catch()

import { getDataFromSheets } from "../../libs/sheets"; export default function handler(req, res) { getDataFromSheets() .then(sheet=> res.status(200).json(sheet)) .catch(err=> console.log(err))
}

Admin | 1 week ago



Relevant Questions