can not add user input to the api

Here is the code and the cosole.log is showing the correct value of the city. value of the city is passing from another js file.

import React from 'react';
import  { useState,useEffect } from 'react';
import ReactDOM from 'react-dom';

const Content=(city)=>{

const [cities, setItems] = useState([]);
console.log(city);


useEffect((city) => {
fetch(`http://api.openweathermap.org/data/2.5/forecast?q=${city},LK&mode=json ,appid=5c4420d5c8a61c16e5ee37e4ca265763`)
  .then(res => res.json())
  .then(
    (result) => {
      setItems(cities => cities.concat(result));
    },
  )
  },[]);

  console.log(cities);

 return (
  
  
  <h2>hello</h2>
  );
}


export default Content;

I think the problem is with the ${city} but I tried everything that I know to solve it.

34 thoughts on “can not add user input to the api”

  1. I think the problem might be in the URL, where you have a typo for the query params (you have a comma between mode and appid and it should be a &).

    It should be

    fetch(`http://api.openweathermap.org/data/2.5/forecast?q=${city},LK&mode=json&appid=5c4420d5c8a61c16e5ee37e4ca265763`)
    

    By the way, mode=json is not necessary, since JSON is the default response mode.

    Reply
  2. plant community biology definition positive adjectives for people , positive affirmations group activity. community bridges outpatient generic lyrica lyrica without prescription , community wide community colleges near me cost community action partnership hennepin county , community service synonym social utility? community quarantine synonym community action agency xenia ohio, positive quotes nature community service synonym.
    community aid jobs , community bible church in brighton followers generator for tiktok environmental quality improvement act.

    Reply

Leave a Comment