Skip to content
Advertisement

Why axios.patch doesn’t change data in ToDoList?

Roughly speaking, I have a ToDoList in which I want to change the written task text. But on demand to find an error. The data from the input that enters the changed text is stored in the state (editingText), with this text I’m trying to replace the value in the ‘text’ column. Does anyone know what could be the problem I’m missing?

 const submitEdits = (item) => {
    axios.patch(`http://localhost:3004/item/${item.id}`, { text: editingText }).then((res) => {
        console.log(res)
    })
    setIdItem(null);
    setEditingText('')
}

My db.json

    {
     "item": [
         {
  "text": "Пошел в свой первый класс",
  "id": 0,
  "data": {
    "year": 2012,
    "day": 25,
    "month": 1
  }
},
{
  "text": "Поступил в институт",
  "id": 1,
  "data": {
    "year": 2007,
    "day": 12,
    "month": 4
  }
},
{
  "id": 2,
  "text": "123",
  "data": {
    "year": 123,
    "day": 12,
    "month": 12
           }
         }
       ]
      }

enter image description here

Advertisement

Answer

Take a look at the request itself. It was written about 3004 port listening. But the request sends to

http://localhost/...

It is without port. Ut has to be like this i guess:

http://localhost:3004/...
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement