-
-
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
Create-react-app linting question #87
Comments
Hey! Sorry for the delay. The examples are laid out for simplicity of the beginner, but technically, you should listen to the linting rules. Wrap |
Also, thanks so much for your support! I love this thing too! That's why I made it lol |
@tobyl is you question answered? Gonna close this if it is :) |
I'm sorry - I didn't get the notifications for your msgs. Yes, this is super-helpful - I'll take your advice - thank you so much! |
If you're having infinite loop problems, either destructure your request object and use the method as a dependency like: const { get, loading } = useFetch(...)
const initializeTodos = useCallback(async () => {
...
}, [get]) or you could do this for on mount const mounted = useRef(false)
useEffect(() => {
if (!mounted.current) {
initializeTodos()
mounted.current = true
}
}) |
Those look like two great options - I'll play around with it, thanks again! |
I have a related question. The lint warns that I don't add useEffect(() => {
async function fetchSomething() {
const data = await get(...)
if (response.ok) {
// ...
}
}
fetchSomething()
}, [get]) // <-- eslint warns that response.ok is not added to dependency I'm |
@rhobot I need to take another look. Thanks for the heads up! |
I haven't had time to try this out yet, but based off of the NOTE portion of the use-deep-compare-effect docs I bet if we wrapped |
That technically works but then eslint will warn that I've also tried with |
I will get to this as soon as possible. Trying to finish up |
@rhobot This should be working correctly in |
I'm still getting linter suggestions that Is this the expected behavior? What's the correct way to deal with this? I'm currently just excluding Using use-http version 1.0.16 |
Try passing |
Hi @alex-cory , got the same question. I'm wondering why adding response to useEffect/useCallback dependency won't cause re-render? Let's say I have three api calls inside the componet
when Call1 fired, the response will be changing, thus will cause a re-render on call2 as well? |
This isn't technically an issue with use-http (which I'm currently in love with for everything fetch-related) but in create-react-app, following the basic usage example create-react-app default linting shows the error
React Hook useEffect has a missing dependency: 'initializeTodos'. Either include it or remove the dependency array react-hooks/exhaustive-deps
. If I follow this guidance, the error changes toThe 'initializeTodos' function makes the dependencies of useEffect Hook (at line 53) change on every render. Move it inside the useEffect callback. Alternatively, wrap the 'initializeTodos' definition into its own useCallback() Hook react-hooks/exhaustive-deps
.The example seems to work exactly as expected without adding to the dependency array, but I'm wondering if this breaks best practices. Is the linter being too fussy? Or should I be modifying the example to follow this rule?
Apologies if this shouldn't be an issue, I can re-post to stackoverflow.com if recommended. Many thanks for this great module!
The text was updated successfully, but these errors were encountered: