Мне нужно передать реквизит в исходное состояние, но когда я получу undefined
для окончательного результата. Рассмотрим код ниже:
constructor (props){
super(props);
const supplier_id = parseInt(localStorage.getItem('id'));
this.state ={
id: props.items_id, // get the items_id from props
supplier_id: supplier_id,
item_name:'',
item_shortDes: '',
item_longDes: '',
price: '',
terms_agreement: '',
Location: '',
selectedFile: null,
}
this.onChange = this.onChange.bind(this);
this.updateItem = this.updateItem.bind(this);
}
updateItem(){
const itemData = this.state
const selectedFile = this.state.selectedFile
console.log(itemData)
const formData = new FormData();
formData.append('json', JSON.stringify(itemData))
formData.append('itemFile', selectedFile)
fetch(`http://localhost:9000.com/api/item/submit`, //call api here
{
method: 'post',
body: formData
})
}
Но я могу видеть мой items_id внутри рендера ()
render() {
const { items_id } = this.props;
console.log(items_id) //i can get my items id here, but why cannot get it on this.state
return (
...
)
}
Мой результат консоли здесь
идентификатор был показан undefined
здесь