NextJs Sending data from Axios to Danfo

71 views Asked by At

I am working on a NextJs page. I have used axios with usestate and useeffect to retreive json data from a web api into a const state apiData'.

.then((res) => {
   setApiData(res.data.Projects);
     console.log(res.data.Projects);
 })

Here is the console.log output:

[
 {
 Name: Project1,
 Number: DM-01
 },
 {Name: Project 2, Number: DM 02}
]

Now, I am able to console.log or apiData.map the data in the nextjs application. But I am unable to map the apiData to danfo dataframe:

const df = new Danfo.DataFrame(apiData)

console.log(df.columns)

I and trying to assign the json received from axios to danfo dataframe.

1

There are 1 answers

0
Mayank Kumar Chaudhari On

To print denfo dataframe, you should use df.print() function. Also make sure your apiData is not null before assigning it to df.

if(apiData) {
  const df = new Danfo.DataFrame(apiData);
  df.print();
}