My FeedDiscussionsHashnode Enterprise
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Unexpected token < in JSON at position 0.I am using react 16.4.0,react-dom 16.4.0 and react-scripts 1.1.14.

Charles Eno's photo
Charles Eno
·Jun 11, 2018

I am having this error as I tried to view the event object on the console:unhandled Rejection (SyntaxError):Unexpected token < in JSON at position 0.I am using react 16.4.0,react-dom 16.4.0 and react-scripts 1.1.14. Here is the App.js: import React from "react";

import Titles from "./components/Titles"; import Form from "./components/Form"; import Weather from "./components/Weather";

const API_KEY = "";

class App extends React.Component{ getWeather = async (e) => { //e.preventDefault(); e.preventDefault(); const city = e.target.elements.city.value; const country = e.target.elements.country.value; const api_call = await fetch(api.openweathermap.org/data/2.5/weather?q=…); const data = await api_call.json(); console.log(data); //console.warn(data.responseText) } render(){ return( <div> <Titles /> <Form getWeather={this.getWeather} /> <Weather /> </div> ); }

}; export default App;

Here is Form.js: import React from "react";

class Form extends React.Component{ render(){ return( <form onSubmit={this.props.getWeather}> <input type="text" name="city" placeholder="City..."/> <input type="text" name="country" placeholder="Country..."/> <button type="submit">Get Weather</button> </form> ); } }

export default Form;