functional component - react js I am running a process . I want to stop that process if user click on stop (stop button is on a diffrent component - Modal )
process function on app.js looks like
const [terminate, setterminate] = useState(false);
const process =()=>{
... some code (has no use of terminate or setterminate)
for(let i=0;i<5;i++){
if(terminate){
break
}
// api call
}
} // process function ends
const stopProcess = ()=>{
setterminate(true)
}
// called a modal and passes stopProcess as prop. and when click stop button in modal, that invoke stopProcess function. but for loop insite process function dont get break
Modal.js
...
<button onClick={stopProcess}></ button >
...
everything works fine, except for does not breaks. function is invoked , tested by console.log("sdf")