-
-
Notifications
You must be signed in to change notification settings - Fork 464
Description
I'm using a library with useLoadScript like this:
const { isLoaded, loadError } = useLoadScript({
googleMapsApiKey: GOOGLE_API_KEY,
libraries: ['places'],
});
And on rerender it always shows: Performance warning! Loadscript has been reloaded unintentionally! You should not pass libraries prop as new array. Please keep an array of libraries as static class property for Components and PureComponents, or just a const variable outside of component, or somewhere in config files or ENV variables
I've reviewed the code and it seems to use wrong comparison for arrays. When I change libraries !== prevLibraries.current into JSON.stringify(libraries) !== JSON.stringify(prevLibraries.current) then it works as expected without performance warnings. However the real solution is probably more complex as the useEffect shouldn't trigger on the array libraries as it is not changed.