0

I have written a pretty easy fetch using ReactJS + Spring boot, but it is not working and I have no idea why, could you help me with that?

React component

import React, { useEffect, useState } from 'react';

export default function ReactComponent(){
    const[models, setModels] = useState([]);
    const[modelName, setModelName] = useState('');

    const fetchModelData = () => {
        fetch("http://localhost:8080/parcer/all")
          .then(response => {
            return response.json()
          })
          .then(data => {
            setModels(data)
          })
      }

    useEffect(() => {
        fetchModelData()
    }, [])

    return(
        <ul>
            {models.map(model => (
                <li key={model.id}>{model.modelName} | {model.price}</li>
            ))}
        </ul>
    )
}

Stacktrace of react app

ERROR
Failed to fetch
TypeError: Failed to fetch
    at <anonymous>:78:39
    at new Promise (<anonymous>)
    at fetch (<anonymous>:77:18)
    at fetchModelData (http://localhost:3000/static/js/bundle.js:153:5)
    at http://localhost:3000/static/js/bundle.js:160:5
    at commitHookEffectListMount (http://localhost:3000/static/js/bundle.js:27190:30)
    at commitPassiveMountOnFiber (http://localhost:3000/static/js/bundle.js:28683:17)
    at commitPassiveMountEffects_complete (http://localhost:3000/static/js/bundle.js:28655:13)
    at commitPassiveMountEffects_begin (http://localhost:3000/static/js/bundle.js:28645:11)
    at commitPassiveMountEffects (http://localhost:3000/static/js/bundle.js:28635:7)

My SpringBoot controller is working fine and I get the right Json at 8080 port

0 Answers0