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

Example useEffect cleanup function? #573

Open
stevenharderjr opened this issue Nov 2, 2022 · 1 comment
Open

Example useEffect cleanup function? #573

stevenharderjr opened this issue Nov 2, 2022 · 1 comment
Assignees
Labels
triage me I really want to be triaged. type: question Request for information or clarification. Not an issue.

Comments

@stevenharderjr
Copy link

stevenharderjr commented Nov 2, 2022

The map is initialized via useEffect, but there is no cleanup function in the example code. Am I missing something?

@stevenharderjr stevenharderjr added triage me I really want to be triaged. type: question Request for information or clarification. Not an issue. labels Nov 2, 2022
@MALDRU
Copy link

MALDRU commented Feb 8, 2023

export const Map = ({ center, zoom, onLoad }) => {
  const ref = useRef()

  const callback = status => {
    if (status === Status.SUCCESS) {
      const map = new window.google.maps.Map(ref.current, {
        center,
        zoom,
      })
      onLoad && onLoad(map)
    }
  }

  return (
    <>
      <MapContainer ref={ref} />
      <Wrapper apiKey={googleMapsKey} callback={callback}></Wrapper>
    </>
  )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage me I really want to be triaged. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants