I have a simple state to handle how much re-records a user can do,
const [retakes, setRetakes] = useState(0);
const onRerecord = () => {
console.log(retakes + 1, "rere");
setRetakes(retakes + 1);
};
The onRerecord
fires every time the user ask for a re-record from react-ziggeo
:rerecordings
<ZiggeoRecorder
apiKey={process.env.ZIGGEO_API_TOKEN}
video={videoToken}
onProcessed={onProcessed}
recordings={3}
onRerecord={onRerecord}
/>
On first re-record the state updates just fine, however after that the state still the same, It just didn't change at all, You can see here how the console.log
s for 1 "rere"
is the same everytime.
Try this- update previous state.
const [retakes, setRetakes] = useState(0);
const onRerecord = () => {
console.log(retakes + 1, "rere");
setRetakes(retakes => retakes + 1);
};