Answer the question
In order to leave comments, you need to log in
How to display data in React?
It is required to pull data from the database and display it through React.
This data is already being pulled from the backend , but I can’t figure out how it can be displayed on the page itself
Answer the question
In order to leave comments, you need to log in
axios or just fetch, write the received data to the hook / state and then access it
import React, { useState,useEffect} from 'react';
export default function MyComponent() {
const [values, setValues] = useState([])
const axiosInstance = Axios.create({
timeout: 5000,
headers: {
'Content-Type': 'application/json',
'accept': 'application/json',
}
});
const apiFunc = async (link) =>{
let result = axioss.get(link);
return await(result)
}
useEffect(() => {
apiFunc('ЛИНК К API').then(res=>{
setValues(res)
})
}, [])
return (
<div>
{values.length > 0 && values.roles.map(item=>{
return (
<div key={item.id}>ID: {item.id} CODE: {item.code}</div>
)
})}
</div>
)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question