Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ Todos
- [ ] tests for GraphQL hooks `useMutation` + `useQuery`
- [ ] tests for stale `response` see this [PR](https://github.com/alex-cory/use-http/pull/119/files)
- [ ] tests to make sure `response.formData()` and some of the other http `response methods` work properly
- [ ] aborts fetch on unmount
- [ ] take a look at how [react-apollo-hooks](https://github.com/trojanowski/react-apollo-hooks) work. Maybe ad `useSubscription` and `const request = useFetch(); request.subscribe()` or something along those lines
- [ ] make this a github package
- [ ] Make work with React Suspense [current example WIP](https://codesandbox.io/s/7ww5950no0)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "use-http",
"version": "0.1.99",
"version": "0.2.0",
"homepage": "http://use-http.com",
"main": "dist/index.js",
"license": "MIT",
Expand Down
7 changes: 4 additions & 3 deletions src/useFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ function useFetch<TData = any>(...args: UseFetchArgs): UseFetch<TData> {
req()
}
}
// Cancel any running request when unmounting to avoid updating state after component has unmounted
// This can happen if a request's promise resolves after component unmounts
return request.abort
}, dependencies)

// Cancel any running request when unmounting to avoid updating state after component has unmounted
// This can happen if a request's promise resolves after component unmounts
useEffect(() => request.abort, [])

return Object.assign<UseFetchArrayReturn<TData>, UseFetchObjectReturn<TData>>(
[request, makeResponseProxy(res), loading as boolean, error],
{ request, response: makeResponseProxy(res), ...request },
Expand Down