Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

349
Views
Change polygon color on hover in react js (functional component)

I am showing multiple polygons on google map and want to change the color of polygon on hover. I am using functional based component. This is how my code looks like:

It's called on hover

const changePolygonBG = (polygon) => {
        if( typeof polygon === 'undefined'){
            return false;
        }
        const currentColor = polygon.fillColor == fillColors[0]
            ? fillColors[1]
            : fillColors[0];
        polygon.setOptions({fillColor: currentColor});
}

Polygon code

<Polygon 
    paths={triangleCoords} 
    onMouseover={ changePolygonBG } 
    onMouseout={ changePolygonBG } 
    strokeOpacity={0.8} 
    strokeWeight={2} 
    fillColor={ fillColors[0] }
    fillOpacity={0.35}
/>

When I hover on polygon, it shows an error: "Uncaught TypeError: polygon.setOptions is not a function"

Codesandbox link

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!