Question

JavaScript - Build with React-Native.js Make a Weather App using an API call

JavaScript - Build with React-Native.js

Make a Weather App using an API call

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import React from "react";
import Weather from "./components/weather";
import Form from "./components/form";
// import SWeather from "./components/stateless_weather";
// import SForm from "./components/stateless_form"
import Titles from "./components/titles";

const Api_Key = "8d2de98e089f1c28e1a22fc19a24ef04";

class App extends React.Component {

state = {

temperature: undefined,
city: undefined,
country: undefined,
humidity: undefined,
description: undefined,
error: undefined
}

//getWeather is a method we'll use to make the api call
getWeather = async (e) => {

const city = e.target.elements.city.value;
const country = e.target.elements.country.value;
e.preventDefault();   
const api_call = await fetch(`http://api.openweathermap.org/data/2.5/weather?q=${city},${country}&appid=${Api_Key}`);
const response = await api_call.json();
console.log(response);
if(city && country){
this.setState({
temperature: response.main.temp,
city: response.name,
country: response.sys.country,
humidity: response.main.humidity,
description: response.weather[0].description,
error: ""
})
}else{
this.setState({
error: "Please input search values..."
})
}
}

render() {

return (

<div>
<div className="wrapper">
<div className="main">
<div className="container">
<div className="row">
<div className="col-xs-5 title-container">
<Titles />
</div>
<div className="col-xs-7 form-container">
<Form loadWeather={this.getWeather} />
<Weather
temperature={this.state.temperature}
city={this.state.city}
country={this.state.country}
humidity={this.state.humidity}
description={this.state.description}
error={this.state.error}
/>
</div>
</div>
</div>
</div>
</div>
</div>

)
}
}
export default App;

Add a comment
Know the answer?
Add Answer to:
JavaScript - Build with React-Native.js Make a Weather App using an API call
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a JSON mobile app using JavaScript: fetch API for 5 authors (Lao Tzu, Abraham L.,...

    Write a JSON mobile app using JavaScript: fetch API for 5 authors (Lao Tzu, Abraham L., Aristotle, Bo Jackson, Leonardo Da V.) inspirational quotes using below links. Describe code in comments, include HTML and style pages to be processed in brackets. Use the below example format for the app: Keep it simple.               https://www.freecodecamp.org/forum/t/free-api-inspirational-quotes-json-with-code-examples/311373 https://type.fit/api/quotes Current Weather Get Weather San Diego, CA Select the city then press button for current weather City: San Diego Condition: scattered clouds Temperature: 71.08 deg...

  • This assignemnt for Android development using Java Weather Forecaster App Goal: Create an app to display...

    This assignemnt for Android development using Java Weather Forecaster App Goal: Create an app to display a weather forecast for the user’s current location Create the app titled Weather Forecaster The first screen will have a textbox for the user to enter a zip code and a button to submit When the user enters the zip code and clicks the button, the app will navigate to the weather forecast screen. The weather forecast screen will show the current weather for...

  • This is involving javascript using react. The problem is to pass 2 variables of data from...

    This is involving javascript using react. The problem is to pass 2 variables of data from a parent component to a child component. Pass these two variables to the child component: user1 = "admin@email.org", user2 = "cust@email.org". -----------------Parent.js----------------- import React from "react"; import ReactDOM from "react-dom"; import GuestApp from "./GuestApp"; class App extends React.Component { constructor(props) { super(props); // Must call this.state = {role: "admin"}; } render() { switch (this.state.role) { case 'guest': return <GuestApp /* Insert the passing data...

  • Write a javascript program that downloads data from an API and displays it on a graph....

    Write a javascript program that downloads data from an API and displays it on a graph. Use a government API. I recommend using jsfiddle or other online editor.

  • Will dislike if you don't code efficiently, you must have knowledge of next.js,vue.js,immutable.js,react,js. Develop an api...

    Will dislike if you don't code efficiently, you must have knowledge of next.js,vue.js,immutable.js,react,js. Develop an api for distance measurements,you can use any database, make it,make tables then implement the api in backend use node.js,then interpret it using frontend(all the above mentioned technologies). Build 8-10 pages(atleast) in the frontend. Don't attempt if no thorough knowledge.

  • Will dislike if you don't code efficiently, you must have knowledge of next.js,vue.js,immutable.js,react,js. Develop an api...

    Will dislike if you don't code efficiently, you must have knowledge of next.js,vue.js,immutable.js,react,js. Develop an api for distance measurements,you can use any database, make it,make tables then implement the api in backend use node.js,then interpret it using frontend(all the above mentioned technologies). Build 8-10 pages(atleast) in the frontend. Don't attempt if no thorough knowledge.

  • Later in the course we will also be using a JavaScript app called CalcPlot3D to visualize...

    Later in the course we will also be using a JavaScript app called CalcPlot3D to visualize phase planes of systems of differential equations. [Note: It does not run on old browsers, but should work well on Chrome, Safari, and Firefox.] Just so you know, there is an older Java applet version of CalcPlot3D. As you will see near the end of my course, some of my example videos in the course are for the Java applet version, but I will...

  • what are the advantages and disadvantages of using system call versus library through API (Application programming...

    what are the advantages and disadvantages of using system call versus library through API (Application programming interface)

  • Website help I am also trying to build a recipe website using an API. here's a...

    Website help I am also trying to build a recipe website using an API. here's a link to the API's https://www.themealdb.com/api.php I just want to know how to get data from it specifically getting recipes By searching on: Search meal by name API: https://www.themealdb.com/api/json/v1/1/search.php?s=Arrabiata List all meals by first letter: API https://www.themealdb.com/api/json/v1/1/search.php?f=a Lookup full meal details by id: API https://www.themealdb.com/api/json/v1/1/lookup.php?i=52772 Lookup a random meal: API: https://www.themealdb.com/api/json/v1/1/random.php List all meal categories: API: https://www.themealdb.com/api/json/v1/1/categories.php List all Categories, Area, Ingredients API: https://www.themealdb.com/api/json/v1/1/list.php?c=list https://www.themealdb.com/api/json/v1/1/list.php?a=list...

  • The policy that tries to restrict your JavaScript code from using AJAX to call domains other...

    The policy that tries to restrict your JavaScript code from using AJAX to call domains other than where it is hosted is called the

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT