简体   繁体   中英

React error “./src/App.js Line 7: 'APIKEY' is assigned a value but never used no-unused-vars”

I create a weather app with React.js from tutorial and now I'm stuck and can't solve this error "./src/App.js Line 7: 'APIKEY' is assigned a value but never used no-unused-vars" . How can I fix this error?

Below is my code:

import React from 'react';
import './App.css';
import Titles from './components/titles';
import Form from './components/form';
import Weather from './components/weather';

const APIKEY = "0bfdbb5c40aa44b13478951b236a0625";

class WeatherApp extends React.Component {

getWeather = async (e) => {
  e.preventDefault();
  const api_call= await fetch('http://api.openweathermap.org/data/2.5/forecast?id=524901&APPID={APIKEY}');
  const response = await api_call.json();
  console.log(response);
}

  render() {
    return (
      <div>
        <Titles/>
        <Form loadWeather={this.getWeather} />
        <Weather/>
      </div>
    )
  }
}

export default WeatherApp;

You can use the template literals. So :

const api_call= await fetch(`http://api.openweathermap.org/data/2.5/forecast?id=524901&APPID=${APIKEY}`);

With the backtites and the $ sign.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM