I
I
InPizzaWeTrust2021-01-19 14:09:44
React
InPizzaWeTrust, 2021-01-19 14:09:44

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 6006bd8ed82a8960104761.png, 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

1 answer(s)
A
Alexander N, 2021-01-19
@wooly

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 question

Ask a Question

731 491 924 answers to any question