관리 메뉴

커리까지

syntaxerror: unexpected token < in json at position 0 본문

react

syntaxerror: unexpected token < in json at position 0

목표는 커리 2021. 7. 4. 14:35
728x90
SMALL
  • 리액트 강의를 따라 하는데 자꾸 이러한 메시지가 뜨면서 값이 나오지 않았다.
  • 그래서 다음과 같은 코드를 추가하니 잘 나왔다.
  callApi = async () => {
    const response = await fetch('/api/customers',{
      headers: {
        'Accept' : 'application / json'
      }
    });
    const body = await response.json();
    return body;
  }
{
      headers: {
        'Accept' : 'application / json'
      }
    }
  • api 주소 다음에 이 부분을 추가하였다.
728x90
LIST