Skip to content

Commit

Permalink
fix update issuse by adding current ref
Browse files Browse the repository at this point in the history
  • Loading branch information
DVGY authored and srghma committed Mar 29, 2021
1 parent af258fb commit 24351fa
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/EditControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ function EditControl(props) {
const drawRef = useRef();
const propsRef = useRef(props);

drawRef.current = createDrawElement(props, context);

const onDrawCreate = (e) => {
const { onCreated } = props;
const container = context.layerContainer || context.map;
Expand All @@ -51,7 +49,8 @@ function EditControl(props) {
});
}
map.on(leaflet.Draw.Event.CREATED, onDrawCreate);

drawRef.current = createDrawElement(props, context);
map.addControl(drawRef.current);
onMounted && onMounted(drawRef.current);

return () => {
Expand All @@ -69,9 +68,9 @@ function EditControl(props) {

React.useEffect(() => {
if (
isEqual(props.draw, propsRef.draw) &&
isEqual(props.edit, propsRef.edit) &&
props.position === propsRef.position
isEqual(props.draw, propsRef.current.draw) &&
isEqual(props.edit, propsRef.current.edit) &&
props.position === propsRef.current.position
) {
return false;
}
Expand Down

0 comments on commit 24351fa

Please sign in to comment.