Estoy haciendo una aplicación meteorológica, mi código se parece a esto:
const Home = () => { const [weather, setWeather] = useState(null); useEffect(() => { // ... setWeather(weatherIGotFromAPI) }) if (weather.current.dt < weather.current.sunrise - 1800 || weather.current.dt > weather.current.sunset + 1800) { const timeOfDay = "night" } else if (weather.current.dt > weather.current.sunrise + 1800 || weather.current.dt < weather.current.sunset + 1800) { const timeOfDay = "day" } else { const timeOfDay = "dawnOrDusk" } return ( <p>{timeOfDay}</p> ) }Cuando inicio el código, dice 'timeOfDay no está declarado'. Puedo solucionar el problema creando la variable timeOfDay fuera de la instrucción if y luego modificándola. También sé que puedo crear un estado separado para timeOfDay. Pero mi pregunta es ¿por qué tengo que hacer esto? ¿Hay algo fundamental aquí que no entiendo?