在我的react应用程序中,在页面加载时,我调用一个API并将该值存储在状态中.当我试图从状态创建JSX元素时,我得到了错误Cannot read properties of undefined (reading 'expire')
.
const [domains, setDomains] = useState([]);
const [records, setRecords] = useState({});
useEffect(() => {
axios.get('zones/domains').then((res) => {
setDomains(res.data)
axios.get('zones/records', {
params: {
l_id: res.data[0].l_id
}
}).then((res) => {
setRecords(res.data)
});
});
}, [])
let table_str = <tr>
<td>SOA</td>
<td>{records.added.expire}</td>
<td>{records.added.value1} {records.added.value2}</td>
</tr>