title: React Native: Animation callback does not access latest state while using hooks
body: <p>hope you all are having a great day.
  I'm new to react native animations and ran into a problem. Problem is that I'm updating the state inside Animation callback like this</p>
  <pre><code>Animated.timing(position, {
    toValue: {
      x: 500,
      y: 0,
    },
    duration: 250,
    useNativeDriver: false,
  }).start(() =&gt; {
    setActiveIndex(activeIndex + 1)
  });
  </code></pre>
  <p>state is updated but when this animation function is called for the second time it does not get access to latest state. If activeIndex is 0 and it runs for first time activeIndex is updated to 1 but when this animation function is called for second time activeIndex is still 0 and it is still updated to 1 and so on. activeIndex is updated outside this callback this only happens inside the callback.</p>
  <p>Any help will be appreciated.</p>