Skip to main content

Weather Dashboard

Real-time weather information at your fingertips

Search Location

Current Weather

Last updated: 10:30 AM
72°F
Partly Cloudy
Feels Like
75°F
Humidity
65%
Wind
8 mph
Pressure
1015 hPa

5-Day Forecast

Monday
75°F
Tuesday
72°F
Wednesday
68°F
Thursday
65°F
Friday
70°F

Settings

Current Weather

Real-time weather information for your selected location

New York City, US

Updated 2 minutes ago

Monday, October 24

4:30 PM Local Time

72°F

Sunny

Feels Like

75°F

Humidity

45%

Wind

8 mph

Pressure

1013 hPa

Visibility

10 km

UV Index

4 (Moderate)

Sunrise & Sunset

Sunrise

6:45 AM

Sunset

5:30 PM

Today's Hourly Forecast

Now

72°

5 PM

70°

6 PM

68°

7 PM

66°

8 PM

65°

9 PM

63°

10 PM

62°

11 PM

60°

Weather data provided by OpenWeatherMap API

5-Day Forecast

Extended weather forecast for New York City, US

Today

October 24

72° / 60°

Sunny

0% chance of rain

Wind

8 mph

Humidity

45%

UV Index

4 (Moderate)

Feels Like

75°

Tomorrow

October 25

68° / 55°

Partly Cloudy

10% chance of rain

Wind

10 mph

Humidity

55%

UV Index

3 (Moderate)

Feels Like

66°

Wednesday

October 26

65° / 53°

Cloudy

30% chance of rain

Wind

12 mph

Humidity

65%

UV Index

2 (Low)

Feels Like

62°

Thursday

October 27

62° / 50°

Light Rain

60% chance of rain

Wind

15 mph

Humidity

75%

UV Index

1 (Low)

Feels Like

58°

Friday

October 28

67° / 54°

Sunny

5% chance of rain

Wind

8 mph

Humidity

50%

UV Index

4 (Moderate)

Feels Like

69°

Precipitation Forecast

Today
Tue
Wed
Thu
Fri

Forecast Options

Weather data provided by OpenWeatherMap API

Error Handling

Error examples and handling strategies

City Not Found Error

The city "Atlantis" could not be found. Please check the spelling or try a different location.

ERROR 404: City not found in our database.

Suggestions:

  • Check for spelling mistakes
  • Try adding a country code (e.g., "London,UK")
  • Search for a larger city nearby

Network Error

Unable to connect to the weather service. Please check your internet connection.

Network Error: Failed to fetch data from API endpoint.

Troubleshooting steps:

  • Check your internet connection
  • Disable any ad-blockers or VPNs that might interfere
  • Try refreshing the page
  • If the problem persists, the weather service might be experiencing downtime

API Authorization Error

Your API key may be invalid or has reached its request limit.

ERROR 401: Unauthorized. Invalid API key or request limit exceeded.

Possible solutions:

  • Check that your API key is valid and active
  • You may have exceeded your daily request limit
  • Consider upgrading to a paid plan if you need more requests

Generic Error Component

Something went wrong

We're having trouble processing your request right now.

Error Handling Implementation

React Error Component:

// ErrorMessage.js
import React from 'react';

const ErrorMessage = ({ type, message, suggestions, onRetry }) => {
  const errorTypes = {
    'not-found': {
      title: 'City Not Found',
      icon: '🔍',
      color: 'red'
    },
    'network': {
      title: 'Network Error',
      icon: '🌐',
      color: 'orange'
    },
    'api': {
      title: 'API Error',
      icon: '🔑',
      color: 'yellow'
    },
    'default': {
      title: 'Error',
      icon: '❌',
      color: 'gray'
    }
  };

  const errorConfig = errorTypes[type] || errorTypes.default;

  return (
    <div className={`error-container ${errorConfig.color}`}>
      <div className="error-icon">{errorConfig.icon}</div>
      <div className="error-content">
        <h3>{errorConfig.title}</h3>
        <p>{message}</p>
        
        {suggestions && (
          <ul className="suggestions">
            {suggestions.map((suggestion, index) => (
              <li key={index}>{suggestion}</li>
            ))}
          </ul>
        )}
        
        <button onClick={onRetry}>Try Again</button>
      </div>
    </div>
  );
};

export default ErrorMessage;

Using the Error Component:

// WeatherDashboard.js
import React, { useState, useEffect } from 'react';
import ErrorMessage from './ErrorMessage';
import { fetchWeatherData } from '../api/weatherService';

const WeatherDashboard = () => {
  const [data, setData] = useState(null);
  const [loading, setLoading] = useState(false);
  const [error, setError] = useState(null);
  const [city, setCity] = useState('New York');

  const fetchData = async () => {
    setLoading(true);
    setError(null);
    
    try {
      const result = await fetchWeatherData(city);
      setData(result);
    } catch (err) {
      if (err.response) {
        if (err.response.status === 404) {
          setError({
            type: 'not-found',
            message: `The city "${city}" could not be found.`,
            suggestions: [
              'Check for spelling mistakes',
              'Try adding a country code (e.g., "London,UK")',
              'Search for a larger city nearby'
            ]
          });
        } else if (err.response.status === 401) {
          setError({
            type: 'api',
            message: 'API key invalid or quota exceeded.',
            suggestions: [
              'Check API key validity',
              'You may have exceeded your daily limit'
            ]
          });
        } else {
          setError({
            type: 'default',
            message: 'An unexpected error occurred.',
            suggestions: ['Please try again later']
          });
        }
      } else if (err.request) {
        setError({
          type: 'network',
          message: 'Unable to connect to weather service.',
          suggestions: [
            'Check your internet connection',
            'The service might be temporarily down'
          ]
        });
      } else {
        setError({
          type: 'default',
          message: err.message,
          suggestions: ['Please try again later']
        });
      }
    } finally {
      setLoading(false);
    }
  };

  useEffect(() => {
    fetchData();
    // Set up polling every 30 seconds
    const interval = setInterval(fetchData, 30000);
    return () => clearInterval(interval);
  }, [city]);

  const handleRetry = () => {
    fetchData();
  };

  return (
    <div className="weather-dashboard">
      {loading && <div className="loading-spinner">Loading...</div>}
      
      {error && (
        <ErrorMessage
          type={error.type}
          message={error.message}
          suggestions={error.suggestions}
          onRetry={handleRetry}
        />
      )}
      
      {!loading && !error && data && (
        <!-- Weather Data Display -->
      )}
    </div>
  );
};

export default WeatherDashboard;

React Error Boundary

In addition to handling API errors, it's important to catch unexpected rendering errors using React's Error Boundary feature:

// ErrorBoundary.js
import React from 'react';

class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hasError: false, error: null, errorInfo: null };
  }

  static getDerivedStateFromError(error) {
    // Update state so the next render will show the fallback UI
    return { hasError: true };
  }

  componentDidCatch(error, errorInfo) {
    // You can log the error to an error reporting service
    console.error("Uncaught error:", error, errorInfo);
    this.setState({
      error: error,
      errorInfo: errorInfo
    });
  }

  render() {
    if (this.state.hasError) {
      // You can render any custom fallback UI
      return (
        <div className="error-boundary">
          <h2>Something went wrong.</h2>
          <p>The application encountered an unexpected error.</p>
          <button onClick={() => window.location.reload()}>
            Refresh the page
          </button>
          {process.env.NODE_ENV === 'development' && (
            <details>
              <summary>Error Details</summary>
              <p>{this.state.error && this.state.error.toString()}</p>
              <p>Component Stack: {this.state.errorInfo?.componentStack}</p>
            </details>
          )}
        </div>
      );
    }

    return this.props.children;
  }
}

export default ErrorBoundary;

Wrap your main application components with this ErrorBoundary to catch unexpected rendering errors:

// App.js
import React from 'react';
import ErrorBoundary from './ErrorBoundary';
import WeatherDashboard from './WeatherDashboard';

function App() {
  return (
    <div className="app">
      <ErrorBoundary>
        <WeatherDashboard />
      </ErrorBoundary>
    </div>
  );
}

export default App;

Settings

Customize your weather dashboard experience

Units

Choose between Celsius and Fahrenheit

°C °F

Choose your preferred wind speed unit

Choose your preferred pressure unit

For visibility and other measurements

Display

Choose between light and dark mode

☀️ 🌙

12-hour or 24-hour clock

Choose how dates are displayed

Choose what to display first

Data & Updates

How often to update weather data

Number of days to forecast

Use your device's location

Store your search history

Use cached data when offline

API Settings

Your API key for the selected weather service

Notifications

Get notified about severe weather

Get morning weather updates

Get notified before it rains

Loading States

Different loading indicators and animations for the application

Full Screen Loader

Loading weather data...

Usage:

{`const [isLoading, setIsLoading] = useState(false);

// In your component:
return (
  <>
    {isLoading && (
      

Loading weather data...

)} {/* Rest of your component */} );`}

Component Loader

Usage:

{`const WeatherCardSkeleton = () => (
  
);`}

Inline Loader

Updating temperature

Last updated:
Just now

Usage:

{`// Inline spinner component
const Spinner = ({ size = 'md' }) => {
  const sizeClasses = {
    sm: 'h-3 w-3',
    md: 'h-5 w-5',
    lg: 'h-8 w-8'
  };
  
  return (
    
      
      
    
  );
};`}
            

Lazy Loading Components

Loading forecast component...

Implementation:

{`import React, { Suspense, lazy } from 'react';

// Lazy load the forecast component
const WeatherForecast = lazy(() => import('./WeatherForecast'));

// Loading fallback component
const ForecastLoadingFallback = () => (
  

Loading forecast component...

); function App() { return (
}>
); }`}

Implementing Loading States with React

Loading States with React Hooks

{`import { useState, useEffect } from 'react';
import axios from 'axios';

const WeatherDashboard = () => {
  const [weatherData, setWeatherData] = useState(null);
  const [isLoading, setIsLoading] = useState(false);
  const [error, setError] = useState(null);
  const [city, setCity] = useState('New York');

  const fetchWeatherData = async () => {
    setIsLoading(true);
    setError(null);
    
    try {
      const API_KEY = process.env.REACT_APP_WEATHER_API_KEY;
      const url = \`https://api.openweathermap.org/data/2.5/weather?q=\${city}&appid=\${API_KEY}&units=metric\`;
      
      const response = await axios.get(url);
      setWeatherData(response.data);
    } catch (err) {
      setError(err.message);
    } finally {
      setIsLoading(false);
    }
  };

  // Poll for weather data every 30 seconds
  useEffect(() => {
    fetchWeatherData();
    
    const intervalId = setInterval(() => {
      fetchWeatherData();
    }, 30000);
    
    return () => clearInterval(intervalId);
  }, [city]);

  return (
    
{isLoading && } {!isLoading && error && ( )} {!isLoading && !error && weatherData && ( )}
); };`}

Using React Query for Better Loading States

{`import { useQuery } from 'react-query';
import axios from 'axios';

const fetchWeather = async (city) => {
  const API_KEY = process.env.REACT_APP_WEATHER_API_KEY;
  const url = \`https://api.openweathermap.org/data/2.5/weather?q=\${city}&appid=\${API_KEY}&units=metric\`;
  const response = await axios.get(url);
  return response.data;
};

const WeatherDashboard = () => {
  const [city, setCity] = useState('New York');
  
  const { data, isLoading, error, refetch } = useQuery(
    ['weatherData', city],
    () => fetchWeather(city),
    {
      refetchInterval: 30000, // Poll every 30 seconds
      staleTime: 15000, // Consider data stale after 15 seconds
      onError: (error) => {
        console.error('Weather data fetch failed:', error);
      }
    }
  );

  return (
    
{isLoading && } {!isLoading && error && ( )} {!isLoading && !error && data && ( )}
); };`}

Loading Animation Examples

Spinner

Dots

Circle

Pulse

Bounce

Ping

Shimmer

Grid

Customize these loading states to match your application's design system.