i want the value of temp from the api call

my console value : {coord: {…}, weather: Array(1), base: “stations”, main: {…}, visibility: 10000, …} base: “stations” clouds: {all: 100} cod: 200 coord: {lon: 73.86, lat: 18.52} dt: 1598779072 id: 1259229 main: {temp: 26.46, feels_like: 25.59, temp_min: 26.46, temp_max: 26.46, pressure: 1005, …} name: “Pune” rain: {1h: 0.16} sys: {country: “IN”, sunrise: 1598748587, sunset: 1598793658} timezone: 19800 visibility: 10000 weather: [{…}] wind: {speed: 7.06, deg: 245} proto : Object

//mycode
import React, { useState, useEffect } from ‘react’;
import { StyleSheet, Text, View , TextInput , Button, TouchableOpacity} from ‘react-native’;

const api ={
key :“api key”,
base:“https://api.openweathermap.org/data/2.5/
}

const App = () => {

const [query, setQuery] = useState(‘’);
const [weather, setWeather] = useState({});

const search =(evt)=>{
if (evt.key === “Enter”) {
fetch(${api.base}weather?q=${query}&units=metric&APPID=${api.key})

  .then(res=>res.json())
   .then(result => {
      setWeather(result);
      setQuery('');
      console.log(result);
    });
}

}
return (
Enter Country name to get Temp
<TextInput title=“press me” onChange={e => setQuery(e.target.value)} value={query} onKeyPress={search} placeholder=“Search…”/>
{weather.name}
{weather.main.temp}

) 

};

export default App;

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.