Using ref in React allows us to access and manipulate DOM elements.
FOLLOW THESE STEPS:
import React, { useRef } from 'react';
Create a refCircle variable within the React component:
let refCircle = useRef(null);
Define the handleCircleRadius function inside the React component:
const handleCircleRadius = () => {
console.log('New Radius', refCircle.getRadius());
};
Utilize the ref and handleCircleRadius method within the Circle component:
<Circle
ref={(ref) => (refCircle = ref)}
defaultCenter={{
lat: parseFloat(12),
lng: parseFloat(12),
}}
defaultEditable={true}
radius={parseFloat(1000)}
center={{
lat: parseFloat(12,
lng: parseFloat(12),
}}
onRadiusChanged={handleCircleRadius}
options={{ strokeColor: '#ff0000' }}
/>
NOTE: The Circle method is imported from the react-google-maps
library.
Library Link: https://www.npmjs.com/package/react-google-maps
https://i.sstatic.net/yF0MP.png
Output Example:
https://i.sstatic.net/2m5Xl.png