I'm new to REACT and learning a ton. I am trying to retrieve my data from a SharePoint list and render it to a page as a table but when I make my axios call, I get the following error. tblData is undefined
I know why I get the error and it's because the this in the axios is different from the outside, so I turned it into an arrow function and it still didn't work. I then assigned the outer this to a variable and used it in the axios scope but that still didn't work. Please help with!!
function Table(props) {
return (
<tr>
<td>{props.title}</td>
<td>{props.fname}</td>
<td>{props.lname}</td>
<td>{props.phone}</td>
<td>{props.age}</td>
</tr>
)
}
function App() {
var endPointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbyTitle('Axios List')/items";
var tbl = this;
axios.get(endPointUrl).then(response => {
tbl.tblData = response.data.value.map(function (data) {
return (
<Table
title={data.Title}
fname={data.FirstName}
lname={data.LastName}
phone={data.Phone}
age={data.age}
/>
)
})
})
return (
{ tblData }
)
}
ReactDOM.render(
<App />,
document.getElementById("app")
)
Any help would be much appreciated.

this. You need to use some component state, i.e.const [tbl, setTbl] = useState({ tblData: []})