So i have a code here of me getting my users data so its like this in postman
now when i do it in frontend its not fetching the data of it this is the hook state of my code
const [records, setRecords] = useState([]);
useEffect(() => {
const fetchUser = async () => {
const records = await axios.get('/api/users')
setRecords(records)
};
fetchUser();
}, [])
and this is the example of me getting the first_name data
<div>
<ul>
{records.map((record, index) => {
return <li key={index}>{record.email_address}</li>
})}
</ul>
</div>
2
Answers
axios.get
returns an HTTP response, not just the contents. Use thedata
property and this should work.It’s returns a response as well. take a look at the following code-