javascript - ReactJS - console.log(ObjectName) //Working console.log(ObjectName.property) //Property not recognized
问题描述
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.
解决方案
最后我做到了:
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>);
}
它正在工作,谢谢!^^
推荐阅读
- git - 即使在安装之后,如何处理缺少的 git.exe 错误?
- java - 在 Java 中屏蔽 XML 中的敏感数据的性能优化方法
- python - 如何过滤Pydatatable框架的I表达式中传递的多个值的观察?
- python - Postgres ON CONFLICT DO UPDATE only non null values in python
- azure - 在 Kusto 中,如何在使用“reduce”运算符时获得额外的列
- ios - IOS谷歌地图标记标题不出现
- javascript - 包含在 Webpack 4 中的部分渲染为文字而不是 HTML
- python - NoneType' 对象没有属性 'group' 错误。Python代码
- c# - 如何在 C# 中获取 SQL Server 的日期时间
- angular - 角度输入搜索无法使用 switchmap,同时还尝试显示一些初始化数据