call axios post with an interval
function postForm(){ var form = new FormData(); form.append("user_id", user_id); axios.post('http://192.168.29.194/expense_calculator/index.php/API/get_all_transaction',form) .then((response) => { console.log('sss',response.data.data); if(response.data.data){ setData(response.data.data); } }); } useEffect(() => { const timer = setInterval(() => postForm, 1000); return () => clearInterval(timer); },[]); Run code snippet
Source: stackoverflow.com