E
E
embiid2021-03-12 10:57:33
React
embiid, 2021-03-12 10:57:33

How to pull data from backend?

There is data from the back: Here is how I want to take this data:

[{"id":1,"name": "1"}, {"id":2,"name": "2"}]

const [data, setData] = useState([])

    useEffect(() => {
        fetch("http://localhost:5001/xxx")
            .then(response => setData(response))
            .catch(error => console.log(error))
    })

    return (
         {
              data.map(item => 
                   <div>{ item }</div>
              )
         }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tigran Abrahamyan, 2021-03-12
@TAbrahamyan

useEffect(() => {
  fetch("http://localhost:5001/xxx")
    .then(data => data.json())
    .then(response => setData(response))
    .catch(error => console.log(error))
}, []);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question