On my api test, it was able to run as the image below. but, when I try to code in React.JS, the user Id cannot be pass in. What is the problem of this?
But when I try to code in front end, the user Id cannot be pass in to api. Consider the code below:
constructor (props){
super(props);
const Users_id = localStorage.getItem('id');
this.state ={
users_id: Users_id,
event_name: '',
event_email: '',
event_description: '',
event_type: '',
event_location: '',
start_date: '',
end_date: '',
history: PropTypes.object.isRequired
}
this.create = this.create.bind(this);
this.onChange = this.onChange.bind(this);
}
create(){
// const loginEmail = localStorage.getItem('loginEmail');
const Users_id = localStorage.getItem('id');
this.setState({Users_id})
// console.log(loginEmail)
PostData('api/event/submit', this.state).then ((result) => {
let responseJSON = result;
console.log(responseJSON);
console.log(this.state)
});
}
The error show in console.log(responseJSON):

//Updated PostData
return new Promise((resolve, reject) => {
fetch( BaseUrl+type, {
method: "POST",
body: JSON.stringify(userData),
Accept: 'application/json',
// mode: 'no-cors',
headers:
{
'Content-Type': 'application/json'
},
})
.then((response) => response.json())
.then((responseJson) => {
resolve(responseJson);
})
.catch((error)=>{
console.error('Error:', error);
})
});

console.log(typeof Users_id)just before updating state.