Skip to content

False performance warning about libraries #238

@si4dev

Description

@si4dev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions