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

Unable to dynamically update Geography component style #322

Open
telam opened this issue Mar 22, 2023 · 1 comment
Open

Unable to dynamically update Geography component style #322

telam opened this issue Mar 22, 2023 · 1 comment

Comments

@telam
Copy link

telam commented Mar 22, 2023

Currently, the style property of the Geography component is unable to be updated dynamically in a functional component. Below is an example of what I am attempting to accomplish.

const States = (props) => {
  const { highlight, geographies, active, setActive, handleClick } = props;
  return geographies.map((geo) => {
    const geoId = geo.properties.geo_id;
    const abbr = geo.properties.iso_3166_2;
    const isActive = active?.properties?.geo_id === geoId;
    // only allow the highlighted states to be clicked on
    const cursor = isActive && highlight ? "pointer" : "default";
    return (
      <Geography
        {...{ "geo-id": geo.geo_id }}
        key={geo.rsmKey}
        stroke="#FFF"
        geography={geo}
        outline={"none"}
        fill={highlight?.indexOf(abbr) >= 0 ? "#0072c0" : "#DDD"}
        onMouseUp={(e) => {
          handleClick(geo.properties);
        }}
        onMouseEnter={(e) => {
          setActive(geo);
        }}
        onMouseLeave={(e) => {
          setActive(null);
        }}
        style={{ cursor: cursor }}
      />
    );
  });
};
@telam
Copy link
Author

telam commented Mar 22, 2023

Disregard this bug. I didn't realize that you could only update the style based on the following keys in the style prop: default, hover, pressed

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

1 participant