I have a scenario like need to call API inside the React function component. If possible how to return the result. I could be able to call the API but the response is available in the variable. Please advise
My sample code
import React from 'react';
import ReactTable from 'react-table'
import 'react-table/react-table.css'
import axios from 'axios';
const Table = (props) => {
const getData = [axios.get("https://lq-time-
tracking.firebaseio.com/user.json").then(function(response) {
console.log(response);
}).catch(function(error) {
console.log(error);
})]
const data = [{getData}];
const columns = [{
id: 'Name',
Header: 'Name',
accessor: data.user
}, {
Header: 'Date',
accessor: 'Date',
}, {
Header: 'Comment',
accessor:'Comment'
}]
return <ReactTable
data={...data}
columns={columns}
pivotBy={ ['Date', 'Name']}
/>
}
export default Table;