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

[Bug] Marker className changes do not change when props change #2465

Open
Benjamin-Willard opened this issue Jan 14, 2025 · 0 comments
Open
Labels

Comments

@Benjamin-Willard
Copy link

Description

When passing className attribute to the Marker's props, it will add the initial state of the class names but when any of those class names have changed they do not impact the marker. I have to useEffect changes and adjust the element's classList doing something like this below:

const hoverStart = () => {
    markerRef.current.addClassName('is-highlight')
  }
  const hoverEnd = () => {
    markerRef.current.removeClassName('is-highlight')
  }

  React.useEffect(() => {
    if (highlight) {
      markerRef.current.addClassName('is-highlight')
    } else {
      markerRef.current.removeClassName('is-highlight')
    }
  }, [highlight])

Expected Behavior

Doing something like this

const classNames = clsx({
     'is-highlight': highlight
});

Should add/remove class names to the Marker if I pass it via

<Marker ref={markerRef} className={classNames}>

...

</Marker>

Steps to Reproduce

Add a class name above that changes the state for example add something like is-selected if it is true, it should add the marker's class names to have is-selected, otherwise remove it.

Environment

Framework version: react-map-gl@7.1.8
Map library: mapbox-gl@3.9.2
Browser: Chrome 131.0.6778.264
OS: Mac Sequoia 15.1.1 (24B91)

Logs

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant