i tryed to send data regularely from react to laravel by using axios into setInterval but it send an empty array.
here is my code:
<code>
const consultationTable=useSelector(state=>state.reducerConsultation.prods_consultee)
useEffect(()=>{
//pour les users authentifiees
const envoiConsultation_prod=async()=>{
await Axios.post('/consultation-prod',{consultationTable:consultationTable})
.then(
(resp)=>{console.log(resp);
// dispatch(unload_for_next_sending())
}
)
.catch(
error=>{
console.log('error.response.data '+error.response.data.message)
if(error.response.data.message==='Unauthenticated.'){
envoiConsultationGuest()
setGuest(true)
//console.log('ca marche')
}
console.log('erreur consultationTable:'+consultationTable)
}
)
}
const intervalId = setInterval(
envoiConsultation_prod,10000);
// return a method in useEffect to clear the interval
/* return ()=>{
console.log('test on Unmounting');
clearInterval(intervalId)
} */
},[])
</code>
<code>
const consultationTable=useSelector(state=>state.reducerConsultation.prods_consultee)
useEffect(()=>{
//pour les users authentifiees
const envoiConsultation_prod=async()=>{
await Axios.post('/consultation-prod',{consultationTable:consultationTable})
.then(
(resp)=>{console.log(resp);
// dispatch(unload_for_next_sending())
}
)
.catch(
error=>{
console.log('error.response.data '+error.response.data.message)
if(error.response.data.message==='Unauthenticated.'){
envoiConsultationGuest()
setGuest(true)
//console.log('ca marche')
}
console.log('erreur consultationTable:'+consultationTable)
}
)
}
const intervalId = setInterval(
envoiConsultation_prod,10000);
// return a method in useEffect to clear the interval
/* return ()=>{
console.log('test on Unmounting');
clearInterval(intervalId)
} */
},[])
</code>
const consultationTable=useSelector(state=>state.reducerConsultation.prods_consultee)
useEffect(()=>{
//pour les users authentifiees
const envoiConsultation_prod=async()=>{
await Axios.post('/consultation-prod',{consultationTable:consultationTable})
.then(
(resp)=>{console.log(resp);
// dispatch(unload_for_next_sending())
}
)
.catch(
error=>{
console.log('error.response.data '+error.response.data.message)
if(error.response.data.message==='Unauthenticated.'){
envoiConsultationGuest()
setGuest(true)
//console.log('ca marche')
}
console.log('erreur consultationTable:'+consultationTable)
}
)
}
const intervalId = setInterval(
envoiConsultation_prod,10000);
// return a method in useEffect to clear the interval
/* return ()=>{
console.log('test on Unmounting');
clearInterval(intervalId)
} */
},[])
it send an empty array,But at first i called consultation_prod directly in useEffect with consultationTable in the array dependencies of useEffect,so it worked perfectly without any issue.