title: Update state from inside a PanResponder
body: <p>I am making an app using react-native-svg and I am having trouble to update the component's state from inside a PanResponder. </p>
  
  <p>I have a &lt; Svg > element with a &lt; Circle > in it. The &lt; Circle >'s position is relative to a variable called originCoords (a state variable). I have used the PanResponder to make it so that, when doing a panning gesture, the &lt; Svg > (with the &lt; Circle > inside it) is moved and, once the gesture's ended, the &lt; Svg > goes back to its original position.</p>
  
  <p>I am trying to make the originCoords change once the panning gesture is finished, so, even though the &lt; Svg > goes back to its original position, the &lt; Circle > remains at its new position. But I am having a real hard time changing the originCoords' state from inside the PanResponder, in the createPanResponder.js file, it just stays the same, at least on the android emulator. Any help would be much appreciated. </p>
  
  <p>Here are my files:</p>
  
  <pre><code>// MapScreen.js
  
  import React, { useRef, useState } from "react";
  import { Animated } from "react-native";
  import { Svg, Circle } from "react-native-svg";
  import { createPanResponder } from "../services/utils/createPanResponder";
  
  export const MapScreen = () =&gt; {
    const [originCoords, setOriginCoords] = useState({x: 0, y: 0});
    const [circleCoords, setCircleCoords] = useState({x: 20, y: 20});
  
    const pan = useRef(new Animated.ValueXY()).current;
    const panResponder = createPanResponder(pan, originCoords, setOriginCoords);
  
    return (
      &lt;Animated.View
        style={{transform: [{ translateX: pan.x }, { translateY: pan.y }],}}
        {...panResponder.panHandlers}
      &gt;
        &lt;Svg width='300' height='300' style={{ backgroundColor: "blue" }}&gt;
          &lt;Circle
            cx={`${circleCoords.x - originCoords.x}`}
            cy={`${circleCoords.y - originCoords.y}`}
            r="5"
            stroke="white"
            strokeWidth="1"
          /&gt;
        &lt;/Svg&gt;
      &lt;/Animated.View&gt;
    );
  };
  </code></pre>
  
  <pre><code>import { useRef } from "react";
  import { PanResponder, Animated } from "react-native";
  
  export const createPanResponder = (pan, originCoords, setOriginCoords) =&gt; {
    return useRef(
      PanResponder.create({
        // PanResponder default configs have been removed to be more succint
        onPanResponderMove: (evt, gestureState) =&gt; {
          // sets pan.x and pan.y to equal gesture's deltas
          Animated.event([{ x: pan.x }])({ x: gestureState.dx });
          Animated.event([{ y: pan.y }])({ y: gestureState.dy });
        },
  
        onPanResponderRelease: (evt, gestureState) =&gt; {
          //resets pan.x and pan.y
          Animated.event([{ x: pan.x }])({ x: 0 });
          Animated.event([{ y: pan.y }])({ y: 0 });
  
          // PROBLEM IS HERE, setOriginCoords DOESN'T DO ANYTHING
          console.log(originCoords); // { x: 0, y: 0 }
          const { dx, dy } = gestureState;
          setOriginCoords({ ...originCoords, dx, dy });
          console.log(originCoords); // { x: 0, y: 0 }
        },
      })
    ).current;
  };
  
  </code></pre>