It should be a simple question. But I can't figure it out. I want to display the database's length of row (Mysql) and I did it by using axios.
Then I push it into an array but it appears the problem!
I can't call the required value [217].
import React ,{useState, useEffect} from 'react';
import axios from 'axios';
import { valueHandler } from 'mssql/lib/base';
function Home() {
const Countrow = [1,2,3]; //these 3 data are for testing
axios.get("http://localhost:3001/api/countStaff").then(res => {
Countrow.push(res.data.length);
// console.log(res.data.length);
console.log('Countrow in axios.get:',Countrow);
})
console.log('Countrow:',Countrow);
console.log('the 4th string of the array is: ',Countrow[4]);
const listinfo = Countrow.map((number) =><li>{number}</li>);
// const numbers = [1];
// console.log(numbers);
// const listItems = numbers.map((number) =><li>{number}</li>);
return (
<div>
Hello World!
<ul>{listinfo}<ul/>
</div>
)
}
export default Home
How can I solve it?