Track your progress, run tests, and get AI feedback
Run code and see test results
Submit and get AI-powered feedback
Track which problems you've solved
Build a Robust useFetch Hook in React with Loading & Error States
This problem challenges you to build a custom useFetch React hook that elegantly handles data fetching, loading states, and error management. You will create a reusable hook to fetch data from a public API and display it within a simple UI, demonstrating robust error handling and user feedback. This task is ideal for practicing custom hooks, state management, and UI rendering based on async operations.
useFetch.useFetch hook should accept a URL string as its primary argument.data, loading (boolean), error (any), and a refetch function.useFetch into /App.tsx to fetch data from a provided public API endpoint.loading is true.error is present, display the error message clearly, perhaps in red text, alongside a "Retry" button.useFetch hook is correctly implemented and adheres to React hook rules.loading, error, or data changes.https://jsonplaceholder.typicode.com/posts for fetching a list of posts.https://jsonplaceholder.typicode.com/invalid-endpoint) in /App.tsx to test error states.useFetch using native fetch API.Constraints
fetch API; no third-party libraries like Axios or React Query for data fetching.useFetch hook should be generic enough to fetch any JSON data.useFetch custom hook.