fetch 함수를 이용해 로그인의 로직을 만들어 보려고 한다
fetch("api주소",{
method : "POST",
body:JSON.stringify({
email: this.state.id,
password: this.state.pw,
}),
})
//비동기처리 가능한 것들만 then에 담을 수 있다.
.then((response)=> response.json())
//response의 네이밍은 상관없다. object형태로 변환하는 과정,body에 담긴 정보만 object로 변환하는 과정
.then((result)=> console.log("결과:", result));
// 위의 then 에 대한 return값이 result에 담긴다.
** then : fetch가 끝나는 것을 기다렸다가 then이 실행된다.
button의에서 onClick 이벤트가 발생할때 백엔드에게
method : post
body 에 담아서 {id:this.state.id, pw:this.state.pw,}
json (stringify)의 형식으로 백엔드와 통신하는 것,