fetch put выдает ошибку
если в методе фетч в боди дать такой объект, то выдает ошибку
TypeError: Converting circular structure to JSON --> starting at object with constructor 'HTMLParagraphElement' | property '__reactInternalInstance$m7vc8fqqli' -> object with constructor 'FiberNode' --- property 'stateNode' closes the circle
const updatedContact = {
id: e.target.id,
name: nameValue,
phone: phoneValue,
email: emailValue
}
но если вот такой объект, где переменные заменить на строки, ошибки нету
const updatedContact = {
id: e.target.id,
name: "dsad",
phone: "dsds",
email: "dsdsds"
}
import React from 'react';
import './contact.scss'
export default class Contact extends React.Component{
_changeContact(e){
console.log(e.target.id)
const nameValue = document.getElementById(`${e.target.id}name`)
const phoneValue = document.getElementById(`${e.target.id}phone`)
const emailValue = document.getElementById(`${e.target.id}email`)
const updatedContact = {
id: e.target.id,
name: nameValue,
phone: phoneValue,
email: emailValue
}
fetch(`http://localhost:3000/contacts/${e.target.id}`, {
method: "PUT",
body: JSON.stringify(updatedContact),
headers: {
'Content-Type': 'application/json',
},
})
.then(response => response.json())
.then(json => console.log(json))
}
render(){
return(
<div className="contact">
<p id={`${this.props.contact.id}name`}>{this.props.contact.name}</p>
<p id={`${this.props.contact.id}phone`}>{this.props.contact.phone}</p>
<p id={`${this.props.contact.id}email`}>{this.props.contact.email}</p>
<button id={this.props.contact.id} onClick={(e)=> this._changeContact(e)}>Изменить</button>
</div>
)
}
}