Accessing up-to-date state from within a callback
For your scenario (where you cannot keep creating new callbacks and passing them to your 3rd party library), you can use useRef to keep a mutable object with the current state. Like so: function Card(title) { const [count, setCount] = React.useState(0) const [callbackSetup, setCallbackSetup] = React.useState(false) const stateRef = useRef(); // make stateRef always have … Read more