4
Questions
5
Answers
1
Gold Badges
2
Silver Badges
2
Bronze Badges
I wrote a custom hook for fetching data. Is this the right way to do it, or am I missing something?
function useFetch(url: string) {
const [data, setData] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
fetch(url)
.then(res => res.json())
.then(setData)
.catch(setError)
.finally(() => setLoading(false));
}, [url]);
return { data, loading, error };
}
Should I use AbortController? What about race conditions?
1
Answers88
Upvotes6300
ViewsI've been using async/await in my Node.js app but I keep running into unhandled promise rejections. Here's my current code:
async function fetchData() {
const res = await fetch('https://api.example.com/data');
const json = await res.json();
return json;
}
What's the correct pattern for catching errors? Should I use try/catch everywhere or is there a better approach?
David Kim
asked 2 months ago2
Answers92
Upvotes4230
ViewsI'm building a web scraper that needs to handle 1000+ URLs concurrently. I've read about three approaches:
My task is HTTP requests (I/O-bound). Is asyncio always the right choice? What's the overhead comparison?
David Kim
asked 2 months ago1
Answers21
Upvotes7600
ViewsI accidentally pushed a commit with sensitive data (API key) to a public GitHub repo. I need to remove it.
I know git revert creates a new commit undoing the changes. But the sensitive data is still in the git history — is that a problem? What's the cleanest way to handle this without breaking my team's workflow?
David Kim
asked 4 months ago2
Answers61
Upvotes14700
Views1