Почему не выводятся данные из запроса в заголовок?

Почему не выводятся данные из запроса в заголовок
<h1 className="place" id="place">City: {props.data.name}</h1>
?
function installWeather(props) {
    const request = new Promise((resolve, reject) => {
        console.log('Запрос данных на сервер...')
        fetch('https://api.openweathermap.org/data/2.5/weather?q=LVIV&units=metric&APPID=5d066958a60d315387d9492393935c19')
            .then(response => {
                if (response.ok) {
                    return resolve(response.json());
                } else {
                    reject('Что-то пошло нет так');
                }

            });
    });
    request
        .then(data => {
            return (
                <div className='wrapper'>
                    <div className='container'>
                        <h1 className="place" id="place">City: {props.data.name}</h1>
                        <p className="temp" id="temp"></p>
                        <p className="pressure" id="pressure"></p>
                        <p className="description" id="description"></p>
                        <p className="humidity" id="humidity"></p>
                        <p className="speed" id="speed"></p>
                        <p className="degree" id="degree"></p>
                        <img className="image" id="image" src="" alt="clouds" title="Weather"/>
                    </div>
                </div>
            )
        })
}
export default installWeather;
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
  • Вопрос задан
  • 88 просмотров
Решения вопроса 1
Lapita12
@Lapita12
Тесты, тесты?
function installWeather(props) {
  const request = new Promise((resolve, reject) => {
    console.log('Запрос данных на сервер...')
    fetch('https://api.openweathermap.org/data/2.5/weather?q=LVIV&units=metric&APPID=5d066958a60d315387d9492393935c19')
      .then(response => {
        if (response.ok) {
          return resolve(response.json());
        } else {
          reject('Что-то пошло нет так');
        }
      });
  });
  
  return request
    .then(data => {
      return (
        <div className='wrapper'>
          <div className='container'>
            <h1 className="place" id="place">City: {data.name}</h1>
            <p className="temp" id="temp"></p>
            <p className="pressure" id="pressure"></p>
            <p className="description" id="description"></p>
            <p className="humidity" id="humidity"></p>
            <p className="speed" id="speed"></p>
            <p className="degree" id="degree"></p>
            <img className="image" id="image" src="" alt="clouds" title="Weather"/>
          </div>
        </div>
      )
    })
}

export default installWeather;
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
06 мая 2024, в 09:38
1200 руб./в час
06 мая 2024, в 09:37
1200 руб./в час
06 мая 2024, в 09:36
8000 руб./за проект