
IP Address Tracker with React typescript
Design comparison
Solution retrospective
-
I'm pleased I was able to render the map to match the design file
-
Building my own custom
useFetch
hook for data fetching which helped me gain more understanding on API handling in React
Next time, I'd probably try working with google API to render maps
What challenges did you encounter, and how did you overcome them?-
Working with TypeScript where I had to specify exact types for API responses and implement type safety for the hook. I went through documentations and I had to reach out to a senior to review what I did. For request validation, I used Zod schema
-
Optimizing API calls making sure it handles loading state and errors properly. I tackled this by building a custom hook for data fetching. (Though I personally don't think I did a good job in the error handling part)
- Managing empty states: so my issue is not knowing how the UI should look if a certain data is not available, and if so, how do I handle the UI, most especially the map rendering in that scenario
- Explicitly handling error status cases in my useFetch hook, meaning specific API errors like 404 or 500
Community feedback
- @its-awaisPosted 10 days ago
look miss, your project is not working because of cross orgin property, you have to define your proxey in your vite file.
0@CrownedTechiePosted 10 days ago@its-awais Hey there, please I'd like more details on what exactly is not working. Is it breaking? a blank page or something? Because I opened the deployed link and it's working fine on my end. So I'm confused
0@its-awaisPosted 10 days ago@CrownedTechie look when i want to look at your project you did not use proxy, because of that your frontend want to access your backend then there port is different, so because you are using react,so you need to define proxy in your vite app so that your frontend access you json file where you get your data
export default defineConfig({
plugins: [react()], server: { proxy: { "/api": "http://localhost:8000", }, }, });
and use this
const response = await axiosInstance.get<TData>(`/api${url}`, { params: { ...params, apiKey: API_KEY, // Optional, if needed }, signal: controller.signal, });
look now i see i use /api over there so now its fixed but change it because i never use typescript i use js so,but your website have cors issue
0@CrownedTechiePosted 9 days ago@its-awais Thank you for the suggestion. Just to clarify, my project isn't a full-stack app; I'm simply fetching data from a free external API to show on the frontend, so the proxy setup in Vite isn't needed since there's no local backend server.
And I’m not actually running into any CORS issues since the data is displaying just fine on the frontend. If there were any issues, the data wouldn’t show up at all. Or are you experiencing otherwise?
0@its-awaisPosted 9 days ago@CrownedTechie i know your project is not an full stack i already know, because i create these project so i know, oky i just tell you what i seen so you understand what i am saying,
ross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://geo.ipify.org/api/v2/country,city?apiKey=at_OnpuI5H6sjJjQyTFJafQ0hAown9Wt. (Reason: CORS request did not succeed). Status code: (null)
know you understand what is problem in your code, so what i mean to say that when you get the data from external api, then external api work as backend, and you're creating frontend so there "cors" is that so they can trust each other.
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord