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

TypeError: can't access property "getStyle", this.map is undefined #38

Closed
eiiot opened this issue Apr 3, 2022 · 5 comments
Closed

TypeError: can't access property "getStyle", this.map is undefined #38

eiiot opened this issue Apr 3, 2022 · 5 comments

Comments

@eiiot
Copy link

eiiot commented Apr 3, 2022

image

I'm attempting to use the styles control w/ react, but occasionally get this error on page load.

I don't know if you're familiar w/ react, but I thought I would double check here anyways

Here's the StylesControl component

import { useControl, Marker, ControlPosition } from 'react-map-gl'
import { StylesControl } from 'mapbox-gl-controls'
import { StyleOption } from 'mapbox-gl-controls/lib/StylesControl/types'

interface StylesControlProps {
  /** Array of style options */
  styles?: StyleOption[]

  /** Triggered on style change */
  position?: ControlPosition

  onLoading?: (e: object) => void
  onChange?: (e: object) => void
  onError?: (e: object) => void
}

/* eslint-disable complexity,max-statements */
export default function MapboxStyleControl(props: StylesControlProps) {
  const styleControl = useControl(
    () => {
      const ctrl = new StylesControl({
        ...props,
      })
      return ctrl
    },
    {
      position: props.position,
    }
  )

  return null
}

Thanks!

@korywka
Copy link
Owner

korywka commented Apr 3, 2022

@eiiot please, provide minimal example on https://codesandbox.io/ 🙏

@eiiot
Copy link
Author

eiiot commented Apr 3, 2022

I'll try my best

@eiiot
Copy link
Author

eiiot commented Apr 3, 2022

https://codesandbox.io/s/condescending-faraday-qxm8le?file=/src/index.js

It doesn't look like the issue is showing up :/

It could be something to do with Next.js

@korywka
Copy link
Owner

korywka commented Apr 3, 2022

Yep, it looks like something with SSR and next.js.

@eiiot
Copy link
Author

eiiot commented Apr 3, 2022

Ugh. *I have SSR disabled I think... let me check

Repository owner locked and limited conversation to collaborators Apr 6, 2022
@korywka korywka converted this issue into a discussion Apr 6, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants