-
-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto managed useFetch doesn't append URL to provider #247
Comments
You are correct! 🙂 That overwrites the url! You are looking for the
then useFetch('https://this-overwrites-the-url.com', []) whereas useFetch({ path: '/this-adds-a-path' }, []) This is also the same functionality for managed state. |
If I were to implement your desired method, it would be a huge breaking change. |
It is a bit odd but i understand that changing it at this point would break things. Thank you for the prompt response. |
I've been deeply thinking about this and if it's worth it. I've been looking at all the patterns that have emerged over the past year. I think the biggest thing is, which feature is used the most and I think |
Well, if we consider the fact that provider is used to set a base URL to be used throughout the provider's children, it would make more sense to append to the base URL by default if it exists. Generally speaking i think the behaviour should be determined based on the URL supplied, which is the way the native fetch method does it. Providing an absolute URL overrides the base URL while providing a relative URL adds to it:
on the off chance that you want to override it you do this:
Following this, i don't see the {path} option being needed anymore. In fact i don't see {url} option being needed either for unmanaged usage since you typically wouldn't be calling |
I think I will change this functionality. I think it greatly increases the understanding of the syntax and also makes it a lot cleaner. I just hate doing all these breaking changes. I also need to update videos. 😅 |
I still think we should have useFetch({ url: 'overwrite-global-url' }) in the case we have a useFetch('/path', { url: 'overwrite-global-url.com' }) this would error^ you would just put this in the useFetch({ url: 'overwrite-global-url.com/path' }) |
Wouldn't automatic detection be more convenient? It's very easy to detect whether the path is absolute or relative |
You're saying check if it starts with |
Yes, the way native fetch does it. |
We have to basically implement our own "automatic detection" as far as I know. Let's say we're at fetch('/path') // fetches `https://example.com/path` and if you do fetch('https://example-2.com/path') // fetches `https://example-2.com/path` now, if our app is rendered in How do you suggest we do this? I think checking for a |
I was thinking For allowing different protocols we can use |
This should be added as of |
Describe the bug
When providing a URL via Provider component, useFetch URL doesn't get appended to Provider URL. This seems to only apply to auto managed useFetch
https://codesandbox.io/s/use-http-provider-bug-1n0mm?file=/src/App.js
To Reproduce
Steps to reproduce the behavior:
Check network tab in codesandbox, first request with empty string uses the Provider's URL, second and third requests don't use the Provider's URL
Expected behavior
The "/test" path should get appended to the provider's URL
The text was updated successfully, but these errors were encountered: