I'm trying to save the data I'm receiving through state but state is always undefined when I try to log it in console to see if it's updating. This is how I'm declaring it
const[lastAction,setLastAction] = useState(undefined);
And this is when I'm updating it :
document.addEventListener('CLICKED_BUTTON', function (e) {
var data = e.detail;
setLastAction(data);
console.log(lastAction);
axios.post('http://127.0.0.1:5000/Tracking',{
message : 'adding',
sessionId : localStorage.getItem('TSid'),
activities : data
}).catch(function(response){
console.log(response);
});
});
the data I'm receiving is an object. What's wrong with my code so it's not saving ? I'm receiving the data from my content script since I'm developing an extension.