Skip to content

Use updated props in PanResponder callbacks

Compare
Choose a tag to compare
@UdaySravanK UdaySravanK released this 25 Dec 21:43
· 32 commits to master since this release
3aa6e77

Issue: Using useRef memoizes initial disable value. So the swipe functionality continues to work though the disabled prop is set as true.
Fix: Use useCallback instead of useRef to update PanResponder callbacks every time props update

Example:

const MyComponent = (props) => {
  const [disableSwipeButton, setDisableSwipeButton] = useState(false)
  return (
    <div>
      <RNSwipeButton disabled={disableSwipeButton} />
      <Button onPress={() => setDisableSwipeButton(!disableSwipeButton)} title="Toggle disable" />
    </div>
  )
}