I want to make a weather app. But the string does not appear on the component I want.
How can innerText be used in React?
This is my Weather.jsx
import React from "react";
const Weather = () => {
const API_KEY = '123456789';
const COORDS = "coords";
const weather = document.getElementById("weather");
const getWeather = (lat, lng) => {
fetch(
`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lng}&appid=${API_KEY}&units=metric`
)
.then(function (response) {
return response.json();
})
.then(function (json) {
const temperature = json.main.temp;
const place = json.name;
weather.innerText = `${temperature}℃,\n ${place}`;
});
};
};
export default Weather;
This is the screen code for the weather to appear.
import React from "react";
import styled from "styled-components";
import Weather from "../../Components/Weather";
const DetailPresenter = () => {
return (
<>
<DetailContainer>
<div id="weather">{Weather()}</div>
</DetailContainer>
</>
);
};
export default DetailPresenter;