I can see array with objects of data "fees" perfectly but if i wanna see a single value like fees[0]?.firstFee i get this error:
Uncaught TypeError: Cannot read properties of undefined (reading '0')
i thought ? operator would avoid this but seems like not...
const [fees, setFees] = useState();
useEffect(() => {
const getFees = async () => {
const res = await axios.get('/api/feesettings', {
headers: { Authorization: token },
});
setFees(res.data);
};
getFees();
}, []);
console.log(fees);
console.log(fees[0]?.firstFee );
Via Active questions tagged javascript - Stack Overflow https://ift.tt/xgEVhpU
Comments
Post a Comment