I'm learning react js, here I am making an input to the database. here I have a problem how to send data with the format FormData (); use hooks ?
const initialFormState = { id: null, id_user: '1', kode: '', qty: '', harga: '' }
const [ibarang, setIbarang] = useState(initialFormState);
const handleInputChange = (e) => {
const { name, value } = e.target
setIbarang({ ...ibarang, [name]: value })
}
const handleSubmitBarang = async (e) => {
e.preventDefault()
console.log(ibarang);
try {
let res = await Axios.post('https://API.COM', ibarang, {
'Content-Type': 'application/x-www-form-urlencoded',
})
console.log(res.data)
if (res.data.status === 200) {
setTimeout(() => {
// history.push("/dashboard")
}, 500);
} else if (res.data.status === 401) {
setalertMessage("Username atau password salah!")
} else {
setalertMessage("Periksa kembali koneksi internet anda")
}
} catch (error) {
setalertMessage("Periksa kembali koneksi internet anda")
}
}