Here is my post api request, I need this data from front-end:
Consider the code below, the users_id
is actually getting from localStorage, while items_id
taken from another api that I have been call from componentDidMount
:
purchaseOrder(){
const Users_id = localStorage.getItem('id'); // get user_id
const items_id = this.state.data.id; // get items_id
console.log(Users_id)
console.log(items_id)
PostData('api/purchase-order-item/submit', this.state).then ((result) => { // how to pass the users id and items id to api?
let responseJSON = result;
console.log(responseJSON);
console.log(this.state)
});
}
this.state :
constructor(props){
super(props);
this.state ={
data: [],
remark: '', //for api
quantity: '', // for api
isLoaded: false,
redirect: false,
history: PropTypes.object.isRequired
}
this.purchaseOrder = this.purchaseOrder.bind(this);
this.onChange = this.onChange.bind(this);
}
First get the remark
and quantity
from the state and then pass a new plain object as the API post data:
const users_id = localStorage.getItem('id'); // get user_id
const items_id = this.state.data.id; // get items_id
const { remark, quantity } = this.state;
PostData('api/purchase-order-item/submit', { remark, quantity, users_id, items_id }).then ((result) => {