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

Preventing consecutive API calls on re-render. #456

Closed
petertdinh opened this issue Mar 30, 2017 · 2 comments
Closed

Preventing consecutive API calls on re-render. #456

petertdinh opened this issue Mar 30, 2017 · 2 comments

Comments

@petertdinh
Copy link

So right now I have multiple tabs on a page and one of these tabs, Location, houses GoogleMapComponent:

import React, { PropTypes } from 'react';
import { withGoogleMap, GoogleMap, InfoWindow, Marker } from 'react-google-maps';
import withScriptjs from 'react-google-maps/lib/async/withScriptjs';

const GoogleMapComponent = withScriptjs(
  withGoogleMap(({
    infoContent,
    onMarkerClick,
    onMarkerClose,
    position,
    showInfo,
  }) => (
    <GoogleMap
      defaultZoom={14}
      defaultCenter={position}
    >
      <Marker
        position={position}
        onClick={onMarkerClick}
      >
      {showInfo && (
          <div>
          <InfoWindow onCloseClick={onMarkerClose}>
            <div>
              {infoContent}
            </div>
          </InfoWindow>
        </div>
      )}
      </Marker>
    </GoogleMap>
  ))
);

export default GoogleMapComponent;

The problem I'm running into is that GoogleMapComponent is making an API call every time I navigate back into it from another tab. Is there a way to cache the component the first time I navigate into the Location tab, and not have it do consecutive API calls when I go in and out of the tab?

@tomchentw
Copy link
Owner

What you can do:

  • Help check the implementation of withScriptjs and see if there's a bug there.
  • Submit a minimal reproducible repository to demo the problem

Thanks

@tomchentw
Copy link
Owner

Also refer to Getting Help section in the README (or #469).

@tomchentw tomchentw reopened this Apr 20, 2017
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

2 participants