Skip to content
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

useEffect executes many times during render when using options #1

Closed
pocesar opened this issue Oct 1, 2019 · 7 comments
Closed

useEffect executes many times during render when using options #1

pocesar opened this issue Oct 1, 2019 · 7 comments

Comments

@pocesar
Copy link

pocesar commented Oct 1, 2019

when using the second parameter, the useEffect gets called many times, leading to multiple calls to onChange, and multiple location changes, even if they aren't happening. either put on the readme that you need to pass an useMemo'ed options object or useMemo inside the hook

@kcoyner
Copy link

kcoyner commented Dec 12, 2019

@pocesar Can you post an example of how you implemented useMemo in this hook? Thank you.

@pocesar
Copy link
Author

pocesar commented Dec 13, 2019

@kcoyner

const settings = useMemo(() => {
  return { enableHighAccuracy: true }
}, [])

const { latitude, longitude, timestamp, accuracy, error } = usePosition(true, settings)

@pumppi
Copy link

pumppi commented Dec 23, 2019

I'm having same issue.

mewben added a commit to mewben/use-position that referenced this issue Feb 6, 2020
this prevents useEffect from running endlessly.
@samhwang
Copy link

Hi @trekhleb

Can you please have at this issue and also the fix provided by @mewben at #8 . This problem has been sitting here for 6 months, and its been super annoying because it triggers the re-render of the component like an infinite loop. :(

@hally9k
Copy link

hally9k commented Apr 16, 2020

@trekhleb
Copy link
Owner

Hey folks, it should be fixed now in 0.0.7. Thanks @mewben for the fix!

@techieeliot
Copy link

techieeliot commented May 13, 2020

@trekhleb I'm having this issue crop up in 0.0.7.

I'm fetching the geolocation using your tool for my weather app data, and it's repeatedly calling the api to fetch the weather.
Screen Shot 2020-05-13 at 4 43 05 PM

Thanks for creating this great tool. How would I reduce the number of times that I'm calling to the API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants