I will need help with the following code please
import React, {useEffect, useState} from "react";
import APIService from './service/ApiService'
export default function App() {
useEffect(() => {
APIService.getAdminApp('KYC').then(donnees => { //stats
updateStats(donnees)
}).catch(function (ex) {
console.log('Erreur de parsing')
});
},[]);
const [stats, updateStats] = useState([]);
const keys = stats.application
console.log(keys)
return(<div>
</div>);
}
The moment i do console.log(keys), the content of the object is displayed correctly.
But when I do console.log(keys.name), the property name is not recognized.
Why? For information, my getAdminApp function in the useEffect uses a GET on an API fetch. Thanks you in advance.
Finally I did:
import React, {useEffect, useState} from "react";
import APIService from './service/ApiService'
export default function App() {
useEffect(() => {
APIService.getAdminApp('KYC').then(donnees => { //stats
updateStats(donnees)
}).catch(function (ex) {
console.log('Erreur de parsing')
});
},[]);
const [stats, updateStats] = useState([]);
const keys = stats.application
const array = stats.statistiqueList
return(<div>
<p>{keys?.name}</p>
<p>{array[0]?.code}</p>
</div>);
}
It's working, thanks you! ^^